Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess, time
- import threading
- from threading import Thread
- process = None
- class SThread (Thread):
- """Thread class with a stop() method. The thread itself has to check
- regularly for the stopped() condition."""
- def __init__ (self, **args):
- super(SThread, self).__init__()
- self._stop = threading.Event()
- def stop (self):
- self._stop.set()
- def stopped (self):
- return self._stop.isSet()
- def run(self):
- global process
- args = ["/bin/bash","./poc.sh"]
- process = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE)
- for line in process.communicate():
- if line:
- print "process:", line,
- if __name__ == '__main__':
- print 'starting'
- t = SThread()
- t.start()
- time.sleep(1)
- print 'killing'
- process.kill()
- print 'stopping'
- t.stop()
Add Comment
Please, Sign In to add comment