我在 Windows 上执行了以下测试代码:
import multiprocessing
import time
def child() :
while True :
time.sleep( 2 )
if __name__ == '__main__' :
multiprocessing.Process( target = child ).start()
while True :
time.sleep( 1 )
如果我按Ctrl-C
当它工作时,我看到two KeyboardInterrupt
例外 - 一个为sleep( 1 )
和一个用于sleep( 2 )
。 main 中的键盘中断是怎么发生的process
转发给孩子process
?毕竟它们是进程,而不是线程:(。
The KeyboardInterrupt
当进程抛出异常时抓住了SIGINT signal http://docs.python.org/2/library/signal.html这表明键盘中断 http://www.kernel.org/doc/man-pages/online/pages/man7/signal.7.html(按 ctrl+c)。
在 Unix/Linux 系统中SIGINT
信号被发送到整个前台进程组 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_02其中包括父进程及其子进程。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)