所以,我有这个程序,它利用多个硒浏览器窗口进行多处理。
这是程序的样子:
pool = Pool(5)
results = pool.map_async(worker,range(10))
time.sleep(10)
pool.terminate()
但是,这等待池中现有的过程完成。我想立即终止所有工人。
multiprocessing.Pool
Pool._pool
attr中的商店工作过程列表,向他们发送信号很简单:
import multiprocessing
import os
import signal
def kill(pool):
# stop repopulating new child
pool._state = multiprocessing.pool.TERMINATE
pool._worker_handler._state = multiprocessing.pool.TERMINATE
for p in pool._pool:
os.kill(p.pid, signal.SIGKILL)
# .is_alive() will reap dead process
while any(p.is_alive() for p in pool._pool):
pass
pool.terminate()