简体   繁体   English

python多处理池解释器中的断言错误

[英]python multiprocessing pool Assertion Error in interpreter

I am writing a sample program to test the usage of multiprocessing pool of workers in python 2.7.2+ 我正在编写一个示例程序来测试python 2.7.2+中多工作池的使用情况

This is the code i have written in the python ubuntu interpreter 这是我在python ubuntu解释器中编写的代码

>>> from multiprocessing import Pool
>>> def name_append(first_name,last_name):
...     return first_name+" "+last_name
...

>>> from functools import partial
>>> partial_name_append=partial(name_append,'kiran')
>>> partial_name_append('acb')
'kiran acb'
>>> abc='kiran'

>>> pool=Pool(processes=4)
>>> pool.map(partial_name_append,abc)
['kiran k', 'kiran i', 'kiran r', 'kiran a', 'kiran n']
>>> pool.close()
>>> pool.join()

>>> pool.map(partial_name_append,abc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 226, in map
    assert self._state == RUN
AssertionError

After i got pickle errors, over my pool of workers code for large data sets, i am trying to do small examples and try to figure out what is the error. 在我得到pickle错误之后,在我的工作池中为大数据集编写代码,我试图做一些小例子并试图找出错误是什么。

I dont understand why the same statement 'pool.map' doesn't work, when it has worked above. 我不明白为什么同样的语句'pool.map'不起作用,当它在上面工作时。 I think i have executed the 'pool map' correctly but i dont understand the reason. 我想我已正确执行了“池地图”,但我不明白原因。

Is this error related to "PicklingError: Can't pickle : attribute lookup builtin .function failed" 此错误与“PicklingError:无法pickle:属性查找内置 .function失败”有关

Can someone help me out ? 有人可以帮我吗 ?

Thanks 谢谢

You typed: 你键入:

>>> pool.close()

from the docs: 来自文档:

close() 关()

Prevents any more tasks from being submitted to the pool. 防止将任何其他任务提交到池中。 Once all the tasks have been completed the worker processes will exit. 完成所有任务后,工作进程将退出。

Of course you can't use the pool anymore, you closed it. 当然你不能再使用游泳池,你关闭它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM