Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
Last active March 22, 2018 12:35
Show Gist options
  • Save xiazhibin/f17e8af5c015997bb7b7f2aba842107c to your computer and use it in GitHub Desktop.
Save xiazhibin/f17e8af5c015997bb7b7f2aba842107c to your computer and use it in GitHub Desktop.
wather for forked thread
class Watcher:
def __init__(self):
self.child = os.fork()
print 'child', self.child
if self.child == 0:
return
self.watch()
def watch(self):
try:
os.wait()
except KeyboardInterrupt as why:
self.kill()
sys.exit()
def kill(self):
try:
os.kill(self.child, signal.SIGKILL)
except OSError as why:
print why
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment