解释器中的python多处理池断言错误 [英] python multiprocessing pool Assertion Error in interpreter

查看:102
本文介绍了解释器中的python多处理池断言错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个示例程序来测试python 2.7.2+中工人的多处理池的使用情况

I am writing a sample program to test the usage of multiprocessing pool of workers in python 2.7.2+

这是我在python ubuntu解释器中编写的代码

This is the code i have written in the python ubuntu interpreter

>>> 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.

我不明白为什么相同的语句"pool.map"在上面已经起作用时不起作用.我认为我已经正确执行了池图",但是我不明白原因.

I dont understand why the same statement 'pool.map' doesn't work, when it has worked above. I think i have executed the 'pool map' correctly but i dont understand the reason.

此错误是否与"PicklingError:无法腌制:属性查找内置.功能失败"

Is this error related to "PicklingError: Can't pickle : attribute lookup builtin.function failed"

有人可以帮我吗?

谢谢

推荐答案

您键入的内容:

>>> pool.close()

来自文档:

close()

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.

这篇关于解释器中的python多处理池断言错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆