python中pool部分进程卡住了,Python multiprocessing.pool崩溃的进程

Well, they're not supposed to crash, but they do anyway. Is there a way to get multiprocessing.Pool, or any other multiprocessing tool to re-start a process that dies? How would I do this otherwise?

Thanks!

Edit: Some background. The process does several things with geometry in Autodesk Maya. Which it does totally fine. The problem is that every once in a while I'll have a file that decides, once it's finished and a new scene is being opened, to completely exit Maya (or mayapy) with no python warnings or errors, or critical process errors from Windows. It just dies. There's not really anything I can do about the crashing unfortunately.

What I'm hoping for is a way to re-start any processes that have died from a crash.

解决方案

Apparently, recently they've changed the behaviour in Python 3.3, to raise an exception in this case:

http://hg.python.org/cpython/rev/6d6099f7fe89

The defect that lead to this ticket is:

http://bugs.python.org/issue9205

However, if you manually spawn the workers (which I usually do when I use multiprocessing), you may try to use the Process.is_alive() function:

http://docs.python.org/dev/library/multiprocessing#multiprocessing.Process.is_alive

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Pythonmultiprocessing.Pool模块和multiprocessing.dummy.Pool模块都是用于创建进程池和线程池的工具。 进程池(multiprocessing.Pool)是一组维护在进程的工作者,它们可以并行地执行任务。该模块是基于multiprocessing模块实现的,它通过创建多个进程来并行执行任务。 下面是一个创建进程池的示例: ``` python import multiprocessing def worker(process_num): print("Process %d is working" % process_num) if __name__ == '__main__': pool = multiprocessing.Pool(processes=4) for i in range(5): pool.apply_async(worker, args=(i,)) pool.close() pool.join() ``` 上面的示例,我们创建了一个包含4个进程进程池,并向进程提交了5个任务,每个任务调用worker函数并传递一个进程编号作为参数。我们使用apply_async方法向进程提交任务,并使用close和join方法管理进程池。 线程池(multiprocessing.dummy.Pool)是一组维护在线程的工作者,它们可以并行地执行任务。该模块是基于threading模块实现的,它通过创建多个线程来并行执行任务。 下面是一个创建线程池的示例: ``` python from multiprocessing.dummy import Pool import time def worker(thread_num): print("Thread %d is working" % thread_num) time.sleep(1) if __name__ == '__main__': pool = Pool(4) for i in range(5): pool.apply_async(worker, args=(i,)) pool.close() pool.join() ``` 上面的示例,我们创建了一个包含4个线程的线程池,并向线程池提交了5个任务,每个任务调用worker函数并传递一个线程编号作为参数。我们使用apply_async方法向线程池提交任务,并使用close和join方法管理线程池。 需要注意的是,线程池和进程池的用法基本相同,但是由于线程在Python不能真正地并行执行,因此线程池的性能可能比进程池差。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值