English 中文(简体)
采用多处理法的误差。 从不可改变的物体读出的集合图
原标题:Errors using multiprocessing.pool map when reading from an immutable object

我试图利用多处理组绘制一些不可变物体的纯功能图。 然而,在我尝试和操作时,我看到终点站有吨的错误(有时长达几分钟),而且通常情况下,花on不得不以不寻常的方式终止。 I m 运行在Windows(XP),使用Python 3.2.2.

import multiprocessing

def do_stuff(v):
    return v.x + v.y

class Vector:
    __slots__ = [ x ,  y ]

    def __setattr__(self, name, value):
        raise AttributeError("Cannot assign values to object {0} of type {1}".format(self, type(self)))

    def __init__(self, x, y = None):
        """Initialize an immutable x, y Vector"""
        object.__setattr__(self,  x , x)
        object.__setattr__(self,  y , y)

if __name__ == "__main__":
    todo = [Vector(1, 2), Vector(3, 4), Vector(-1, 12), Vector(16, 32), Vector(16, 32)]
    pool = multiprocessing.Pool(4)
    results = list(pool.map(do_stuff, todo))
    print(results)

预期产出:

[3, 7, 11, 48, 48]

错误数目非常大,但似乎在集合中消失。 • 绘制图,试图把属性定在一位卫士上:

Process PoolWorker-1:
Traceback (most recent call last):
  File "c:Python32libmultiprocessingprocess.py", line 267, in _bootstrap
Process PoolWorker-2:
Traceback (most recent call last):
  File "c:Python32libmultiprocessingprocess.py", line 267, in _bootstrap
    self.run()
  File "c:Python32libmultiprocessingprocess.py", line 116, in run
    self._target(*self._args, **self._kwargs)
  File "c:Python32libmultiprocessingpool.py", line 102, in worker
    task = get()
  File "c:Python32libmultiprocessingqueues.py", line 378, in get
    return recv()
  File "d:Documents and SettingsUserdirScripts	emp	est.py", line 11, in __s
etattr__
    raise AttributeError("Cannot assign values to object {0} of type {1}".format
(self, type(self)))
AttributeError: Cannot assign values to object <__main__.Vector object at 0x00C2
BBB0> of type <class  __main__.Vector >

我可以评论从<代码>__slots__ (strange?)开始的行文,使用一个固定的<代码><>>>>>/代码,或者我能够使Verctor阶层的 mu变(制定setattr__),而其中任何一个人将自己造成工作罚款。

www.un.org/spanish/ecosoc 当我从物体读到时,为什么会试图把属性定在我的物体上?

www.un.org/spanish/ecosoc 为什么删除<代码>__slots__ ∗∗∗∗

EDIT:

我正在使用<代码>__slots__,作为保存记忆/空间的一种方式,因为我的节目中通常有大量的病媒。 因此,我无法从图中得出以下结论: 不能为来自不同类型,如长、体和图的班级工作。

最佳回答
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签