This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年04月02日 15:06 by cool-RR, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg102172 - (view) | Author: Ram Rachum (cool-RR) * | Date: 2010年04月02日 15:06 | |
Currently, when you create a Process, all arguments you pass to its __init__ get pickled. I understood this is done because arguments to __init__ almost always become attributes to the Process. Like this: def MyProcess(multiprocessing.Process): def __init__(self, whatever): self.whatever = whatever Of course, attributes must be pickled so they can be accessed from the separate process (on Windows). And indeed in most cases all arguments to __init__ become attributes, so this makes sense. But, in some cases you pass in arguments to __init__ that do not become attributes. In my case, __init__ takes an object, and takes some attributes of this object as attributes to itself. The object is unpicklable, but the attributes are. So I had to make some ugly workaround to make the program run. So I think it would be better if Process would be smart enough to pickle only the arguments that get set as attributes. |
|||
| msg102173 - (view) | Author: Ram Rachum (cool-RR) * | Date: 2010年04月02日 15:07 | |
Sorry, I accidentally typed "def" instead of "class" in my code sample. |
|||
| msg162525 - (view) | Author: Richard Oudkerk (sbt) * (Python committer) | Date: 2012年06月08日 12:46 | |
As long as you don't pass the arguments on to Process.__init__() when you call it there should be no problem. The following program works, but will fail with RuntimeError if you uncomment the comment line: from multiprocessing import Process class Unpicklable(object): def __reduce__(self): raise RuntimeError class MyProcess(Process): def __init__(self, foo, unpicklable_bar): Process.__init__(self, #args=(foo, unpicklable_bar) ) self.foo = foo self.baz = str(unpicklable_bar) def run(self): print(self.foo) print(self.baz) if __name__ == '__main__': p = MyProcess([1,2,3], Unpicklable()) p.start() p.join() |
|||
| msg162624 - (view) | Author: Richard Oudkerk (sbt) * (Python committer) | Date: 2012年06月11日 15:46 | |
I don't think there is any problem here since you have control over which arguments you pass to __init__. Without a reason why that is not a solution I will eventually close the issue as rejected. |
|||
| msg162627 - (view) | Author: Ram Rachum (cool-RR) * | Date: 2012年06月11日 16:21 | |
I opened this issue 2 years ago, and I don't remember it being easily solvable back then. But I've long forgotten what the problems were, and I've lost personal interest in it, so I guess we'll just let it go. |
|||
| msg162630 - (view) | Author: Richard Oudkerk (sbt) * (Python committer) | Date: 2012年06月11日 17:04 | |
OK, I'll close. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:59 | admin | set | github: 52536 |
| 2012年06月11日 17:04:42 | sbt | set | status: open -> closed messages: + msg162630 |
| 2012年06月11日 16:21:36 | cool-RR | set | status: pending -> open messages: + msg162627 |
| 2012年06月11日 15:46:10 | sbt | set | status: open -> pending resolution: rejected messages: + msg162624 stage: resolved |
| 2012年06月08日 12:46:22 | sbt | set | nosy:
+ sbt messages: + msg162525 |
| 2011年02月23日 14:39:38 | cool-RR | set | versions: + Python 3.3, - Python 3.2 |
| 2010年07月11日 02:00:15 | terry.reedy | set | versions: - Python 2.6, Python 3.1, Python 2.7, Python 3.3 |
| 2010年04月02日 15:07:44 | cool-RR | set | messages: + msg102173 |
| 2010年04月02日 15:06:48 | cool-RR | create | |