Python 为什么孩子们没有死?
我期望Python 为什么孩子们没有死?,python,linux,multiprocessing,Python,Linux,Multiprocessing,我期望terminate()方法终止这两个进程: import multiprocessing import time def foo(): while True: time.sleep(1) def bar(): while True: time.sleep(1) if __name__ == '__main__': while True: p_foo = multiprocessing.Process(target
terminate()
方法终止这两个进程:
import multiprocessing
import time
def foo():
while True:
time.sleep(1)
def bar():
while True:
time.sleep(1)
if __name__ == '__main__':
while True:
p_foo = multiprocessing.Process(target=foo, name='foo')
p_bar = multiprocessing.Process(target=bar, name='bar')
p_foo.start()
p_bar.start()
time.sleep(1)
p_foo.terminate()
p_bar.terminate()
print p_foo
print p_bar
运行该代码将提供:
<Process(foo, started)>
<Process(bar, started)>
<Process(foo, started)>
<Process(bar, started)>
...
...
我期待着:
<Process(foo, stopped)>
<Process(bar, stopped)>
<Process(foo, stopped)>
<Process(bar, stopped)>
...
...
因为函数只向进程发送SIGTERM信号,但,所以您可以休眠一段时间,或用于进程终止(信号接收)
例如,如果在终止后添加字符串
time.sleep(.1)
,则可能会终止该字符串。+1表示漂亮的头线。可能是重金属唱片的标题。多重处理总是让这些令人尴尬的可怕评论关于死去的孩子变成僵尸,杀死他们的父母等等。真是太棒了