我将Process类继承到一个类中,我称之为EdgeRenderer。我想使用multiprocessing.Pool
,除了常规进程之外,我希望它们是我的EdgeRenderer的实例。可能?怎么样?Python多处理:自定义进程池
5
A
回答
3
从杰西洛勒尔:
目前还不支持 API中,但不会是一个坏加成。 我会看看添加它来 python2.7/2.6.3 3.1本周
2
我在API中看不到任何钩子。您可能能够通过使用initializer
和initargs
参数来复制所需的功能。或者,你可以建立功能分为可调用的对象,您使用的映射:
class EdgeRenderTask(object):
def op1(self,*args):
...
def op2(self,*args):
...
p = Pool(processes = 10)
e = EdgeRenderTask()
p.apply_async(e.op1,arg_list)
p.map(e.op2,arg_list)
2
这似乎工作:
import multiprocessing as mp
ctx = mp.get_context() # get the default context
class MyProcess(ctx.Process):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print("Hi, I'm custom a process")
ctx.Process = MyProcess # override the context's Process
def worker(x):
print(x**2)
p = ctx.Pool(4)
nums = range(10)
p.map(worker, nums)
相关问题
- 1. Python多处理。与许多进程池
- 2. python多处理池vs进程?
- 3. 多处理Python池
- 4. python多处理池终止
- 5. 池多重处理Python
- 6. Python:多处理产量池
- 7. python多处理池超时
- 8. Python多处理进程号
- 9. Python多处理:最大。池工作进程的数量?
- 10. Python多处理池无法创建足够的进程
- 11. 守护进程中的Python多处理池
- 12. 进程无法停止在python多处理池中
- 13. Python多进程处理进程名称
- 14. Python多处理池功能没有定义
- 15. 如何从python的多处理池中打印进程的进程名称
- 16. Python多进程池进程数
- 17. Python多处理:来自进程的进度报告
- 18. Python多处理:如何关闭异常时的多处理池
- 19. 多处理池3
- 20. Python多处理的限制。池
- 21. Python多处理池未启动作业
- 22. 分析一个python多处理池
- 23. 使用Python多处理池的功能
- 24. python多处理中池的用途
- 25. python 2.5.2多处理池行为
- 26. python tempfile和多处理池错误
- 27. Python的多处理池无法完成
- 28. Python多处理池地图和imap
- 29. Python例程运行速度慢得多,多处理。池
- 30. 显示Python多处理池地图调用的进度?
你们是不是要这样写代码中使用多线程? – 2009-04-11 23:27:40
多处理。 – 2009-04-12 10:04:26