- 如题,我用subprocess创建了一个子进程,这个进程可能要运行很长时间,所以在linux下可以给父进程注册了SIGCHLD信号,查资料后大致代码如下,当子进程退出时父进程获取这个信号进行相应处理。但是移植到windows下,并没有这个信号,需要如何处理呢?
- 目前关键部分代码如下:
def exit_hanlder(signum, frame):
logging.info('receive SIGCHLD')
try:
while True:
cpid, status = os.waitpid(-1, os.WNOHANG)
if cpid == 0:
logging.info('no child process was immediately available')
break
exitcode = status >> 8
logging.info('child process %s exit with exitcode %s', cpid, exitcode)
except OSError as e:
if e.errno == errno.ECHILD:
logging.warning('current process has no existing unwaited-for child processes.')
else:
raise
logging.info('handle SIGCHLD end')
signal.signal(signal.SIGCHLD, exit_hanlder)
可以参考这个回答,调用
WaitForMultipleObjects
APIhttps://stackoverflow.com/que...