def wait_child(pid):
while True:
try:
# wait for child process
wpid, sts = os.waitpid(pid, 0)
except KeyboardInterrupt:
# handle exceptions when parent is waiting
handle_parent_exit(pid)
# if child process stopped
if os.WIFSTOPPED(sts):
continue
# if receive keybord interuption or kill signal
elif os.WIFSIGNALED(sts):
return sts
# seems not work
elif os.WIFEXITED(sts):
return sts
else:
raise "Not stopped, signaled or exited???"
评论列表
文章目录