Skip to content

load_session() fails when dump_session() is used with byref=True #462

@leogama

Description

@leogama

load_session() is failing even in the simplest cases when dump_session() was used with the byref parameter set to True:

>>> import dill
>>> x = 1
>>> dill.dump_session(byref=True)
# restart the interpreter, or not
>>> x = 0
>>> dill.load_session()
>>> x
0
# should have updated 'x' value
>>> del x
>>> dill.load_session()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/leogama/.local/lib/python3.8/site-packages/dill/_dill.py", line 423, in load_session
    _restore_modules(main)
  File "/home/leogama/.local/lib/python3.8/site-packages/dill/_dill.py", line 383, in _restore_modules
    exec("from %s import %s" % (module, name), main_module.__dict__)
  File "<string>", line 1, in <module>
ImportError: cannot import name 'x' from '__main__' (unknown location)

Am I missing something? I tried to take a look at what happens differently when the byref option is used, but I don't understand the manipulations made to the __main__ module.


My setup:

  • Ubuntu 20.04.4 LTS
  • Linux 5.4.0-107
  • Python 3.8.10
  • dill 0.3.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions