本文介绍了python多进程没有正确完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是完成子进程,我使用多进程库,并且在带有返回或退出行的一台机器上,进程在加入之前死亡,但在另一台机器上没有.这些过程总是在增长,并且在完成工作后它们都不会完成.两台机器的python版本都是2.7.3rc2.
My problem is finishing subprocess, I use multiprocess library and in one machine with the return or exit line, the process die before the join, but in another machine not. The processes always grow and neither of them finish after do its job. In both machines the version of python is 2.7.3rc2.
semaphore_processes_limit = BoundedSemaphore(value=PROCS_LIMIT)
# Starting searches
procs = []
for word in words:
semaphore_processes_limit.acquire()
p = Process(target=searching, args=(word,))
procs.append(p)
p.start()
# Wait for all worker processes to finish
for p in procs:
p.join()
# Process
def searching(word):
return # or exit(0)
谢谢.
推荐答案
服务器有 12 个 CPU(Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz, 1200 MHz)并安装了 GNU/Linux Debian Weezy.
The server has 12 CPUs (Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz, 1200 MHz) and has installed GNU/Linux Debian Weezy.
我暂时的丑陋解决方案是:
My temporal ugly solution was:
os.kill(os.getpid(), 9)
这篇关于python多进程没有正确完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!