Created
March 10, 2015 09:31
-
-
Save criloz/8f3e3e5aef510250a7cc to your computer and use it in GitHub Desktop.
is_parent_running with parent_pid
This file contains 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
from multiprocessing import Process | |
import time | |
import os | |
def is_parent_running(pid): | |
try: | |
os.kill(pid, 0) | |
return True | |
except OSError: | |
return False | |
def child_waiting_for_parent(parent_pid): | |
print "waiting for parent to exit" | |
while True: | |
time.sleep(1) | |
print parent_pid | |
print is_parent_running(parent_pid) | |
if __name__ == "__main__": | |
p = Process(target=child_waiting_for_parent, args=(os.getpid(),)) | |
p.start() | |
while True: | |
time.sleep(5) | |
# random error | |
kofsaasnf |
Author
criloz
commented
Mar 10, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment