You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Can't pickle local object" when uses functools.partial with method and args... #73703
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2017-12-20.20:14:36.717>created_at=<Date2017-02-09.21:41:25.021>labels= ['invalid', 'type-bug', 'library', 'expert-asyncio']
title='"Can\'t pickle local object" when uses functools.partial with method and args...'updated_at=<Date2017-12-20.20:14:36.715>user='https://bugs.python.org/DAVIDALEJANDROPineda'
I'm working in a real time data collector project. I'm using asyncio and multiprocessing (run_in_executor).
In python 3.5 worked fine but in python 3.6 not, gave to me this error:
"Traceback (most recent call last):
File "/usr/local/lib/python3.6/multiprocessing/queues.py", line 241, in _feed
obj = _ForkingPickler.dumps(obj)
File "/usr/local/lib/python3.6/multiprocessing/reduction.py", line 51, in dumpscls(buf, protocol).dump(obj)
AttributeError: Can't pickle local object 'WeakSet.__init__.<locals>._remove'
"
I tracked and the problem is when i run some method in run_in_executor with the functools.partial.
Before this version the system works fine.
The main file is local.py (to run with local administration using a socket)
And the engine is in engine.py
Now
I try again with different ways to run a method with args, without args works fine to insert in the executor.
I find there are big differences with file functools betwen versions 3.5.1 to 3.6.0.
Here a more simple example for test the functools: https://github.com/dpineiden/async_multiprocessing
In python 3.5.1 works fine even if in the mprocess file uncomment the 'functools.partial'. But when i use a larger version, like 3.6, fails with the 'weakref'
If the example worked on old versions of Python, perhaps this is a regression. Either WeakSet was pickleable or it was not used in that asyncio/multiprocessing use. If this is a regression in the stdlib it should be fixed.
Since WeakSet never was pickleable, the difference perhaps in the use of WeakSet in asyncio. BaseEventLoop contains a WeakSet attribute since 3.6, this makes it non-pickleable.
Activity
DAVIDALEJANDROPineda commentedon Feb 9, 2017
Hello.
I tracked and the problem is when i run some method in run_in_executor with the functools.partial.
Before this version the system works fine.
The main file is local.py (to run with local administration using a socket)
And the engine is in engine.py
The project (in development):
https://gitlab.com/pineiden/collector
DAVIDALEJANDROPineda commentedon Feb 15, 2017
Now
I try again with different ways to run a method with args, without args works fine to insert in the executor.
I find there are big differences with file functools betwen versions 3.5.1 to 3.6.0.
Here a more simple example for test the functools:
https://github.com/dpineiden/async_multiprocessing
serhiy-storchaka commentedon Mar 13, 2017
Please provide your code as a text, not a picture.
1st1 commentedon Mar 13, 2017
Well, I don't think we can do something about it. Just re-pack your arguments from WeakSet to a regular set.
DAVIDALEJANDROPineda commentedon Mar 14, 2017
Hello Again.
The problem can be replicated in the same structure when call the 'functools.partial' feature
I wrote a simple example. It uses the asyncio and multiprocessing structure.
https://github.com/dpineiden/async_multiprocessing
With this dependences:
https://gitlab.com/pineiden/tasktools
https://gitlab.com/pineiden/networktools
In python 3.5.1 works fine even if in the mprocess file uncomment the 'functools.partial'. But when i use a larger version, like 3.6, fails with the 'weakref'
serhiy-storchaka commentedon Mar 14, 2017
If the example worked on old versions of Python, perhaps this is a regression. Either WeakSet was pickleable or it was not used in that asyncio/multiprocessing use. If this is a regression in the stdlib it should be fixed.
vstinner commentedon Mar 14, 2017
Can you write a short Python script producing the bug?
serhiy-storchaka commentedon Jun 17, 2017
Since WeakSet never was pickleable, the difference perhaps in the use of WeakSet in asyncio. BaseEventLoop contains a WeakSet attribute since 3.6, this makes it non-pickleable.
I'm not sure this is a cause of the failure.
asvetlov commentedon Dec 20, 2017
asyncio objects are not pickable and shouldn't be -- they are ephemeral.
Like pickling open socket object doesn't make sense -- there is no possibility to restore connection to peer on unpickling.
Not sure if we can do anything here.
I suggest closing the issue.
1st1 commentedon Dec 20, 2017
Closing this one.
Quoting my other comment from this issue: