Guest User

Untitled

a guest
Apr 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import subprocess, time
  2. import threading
  3. from threading import Thread
  4.  
  5. process = None
  6.  
  7. class SThread (Thread):
  8. """Thread class with a stop() method. The thread itself has to check
  9. regularly for the stopped() condition."""
  10.  
  11. def __init__ (self, **args):
  12. super(SThread, self).__init__()
  13. self._stop = threading.Event()
  14.  
  15. def stop (self):
  16. self._stop.set()
  17.  
  18. def stopped (self):
  19. return self._stop.isSet()
  20.  
  21. def run(self):
  22. global process
  23. args = ["/bin/bash","./poc.sh"]
  24. process = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE)
  25. for line in process.communicate():
  26. if line:
  27. print "process:", line,
  28.  
  29. if __name__ == '__main__':
  30. print 'starting'
  31. t = SThread()
  32. t.start()
  33. time.sleep(1)
  34. print 'killing'
  35. process.kill()
  36. print 'stopping'
  37. t.stop()
Add Comment
Please, Sign In to add comment