Skip to content

Cannot pickle nested function that refers to itself #62

@mehrdadn

Description

@mehrdadn

The following code does not work, and may be a potential bug:

>>> def f():
    def g(): return g
    return g
>>> import cloudpickle; cloudpickle.dumps(f())
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import cloudpickle; cloudpickle.dumps(f())
  File "cloudpickle.py", line 629, in dumps
    cp.dump(obj)
  File "cloudpickle.py", line 111, in dump
    raise pickle.PicklingError(msg)
PicklingError: Could not pickle object as excessively deep recursion required.

Is it possible to fix this, or is this a fundamental limitation of closures in Python that cannot be worked around?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions