terminate()
メソッドが2つのプロセスを強制終了することを期待していました:
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)>
...