Last active
March 22, 2018 12:35
-
-
Save xiazhibin/f17e8af5c015997bb7b7f2aba842107c to your computer and use it in GitHub Desktop.
wather for forked thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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