Skip to content

"Can't pickle local object" when uses functools.partial with method and args... #73703

Closed

Description

@DAVIDALEJANDROPineda
BPO 29517
Nosy @freddrake, @vstinner, @giampaolo, @asvetlov, @serhiy-storchaka, @1st1
Files
  • code_with_bug.png: Code with bug
  • 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 = None
    closed_at = <Date 2017-12-20.20:14:36.717>
    created_at = <Date 2017-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 = <Date 2017-12-20.20:14:36.715>
    user = 'https://bugs.python.org/DAVIDALEJANDROPineda'

    bugs.python.org fields:

    activity = <Date 2017-12-20.20:14:36.715>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-12-20.20:14:36.717>
    closer = 'yselivanov'
    components = ['Library (Lib)', 'asyncio']
    creation = <Date 2017-02-09.21:41:25.021>
    creator = 'DAVID ALEJANDRO Pineda'
    dependencies = []
    files = ['46614']
    hgrepos = []
    issue_num = 29517
    keywords = []
    message_count = 10.0
    messages = ['287459', '287887', '289551', '289553', '289560', '289567', '289575', '296244', '308801', '308802']
    nosy_count = 7.0
    nosy_names = ['fdrake', 'vstinner', 'giampaolo.rodola', 'asvetlov', 'serhiy.storchaka', 'yselivanov', 'DAVID ALEJANDRO Pineda']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29517'
    versions = ['Python 3.6']

    Activity

    1. DAVIDALEJANDROPineda commented on Feb 9, 2017

      DAVIDALEJANDROPinedamannequin
      MannequinAuthor

      Hello.

      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 dumps
          cls(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

      The project (in development):
      https://gitlab.com/pineiden/collector

    2. added
      type-bug
      on Feb 9, 2017
    3. DAVIDALEJANDROPineda commented on Feb 15, 2017

      DAVIDALEJANDROPinedamannequin
      MannequinAuthor

      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

    4. serhiy-storchaka commented on Mar 13, 2017

      @serhiy-storchaka
      Member

      Please provide your code as a text, not a picture.

    5. 1st1 commented on Mar 13, 2017

      @1st1
      Member

      AttributeError: Can't pickle local object 'WeakSet.__init__.<locals>._remove'

      Well, I don't think we can do something about it. Just re-pack your arguments from WeakSet to a regular set.

    6. DAVIDALEJANDROPineda commented on Mar 14, 2017

      DAVIDALEJANDROPinedamannequin
      MannequinAuthor

      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'

    7. serhiy-storchaka commented on Mar 14, 2017

      @serhiy-storchaka
      Member

      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.

    8. vstinner commented on Mar 14, 2017

      @vstinner
      Member

      Can you write a short Python script producing the bug?

    9. serhiy-storchaka commented on Jun 17, 2017

      @serhiy-storchaka
      Member

      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.

    10. added
      stdlib
      on Jun 17, 2017
    11. asvetlov commented on Dec 20, 2017

      @asvetlov
      Contributor

      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.

    12. 1st1 commented on Dec 20, 2017

      @1st1
      Member

      Closing this one.

      Quoting my other comment from this issue:

      Well, I don't think we can do something about it. Just re-pack your arguments from WeakSet to a regular set.

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtopic-asynciotype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions