Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes some bugs when using dump_session() with byref=True #463

Merged
merged 18 commits into from
May 1, 2022

Commits on Apr 22, 2022

  1. fix dump_session(byref=True) bug when no objetcts are imported from…

    … modules
    
    When no objects are found to be imported from external modules, `_stash_modules()` should return `main_module` unmodified, and not the pair list of objects created from it (`original`).
    leogama authored Apr 22, 2022
    Configuration menu
    Copy the full SHA
    b98cd44 View commit details
    Browse the repository at this point in the history
  2. fix dump_session(byref=True) bug when the multiprocessing module …

    …was imported
    
    Just calling `import multiprocessing` creates a `'__mp_main__'` entry in `sys.modules` that is simply a reference to the `__main__` module. In the old version of the test for module membership, objects in the global scope are wrongly attributed to this virtual `__mp_main__` module. And therefore `load_session()` fails. Testing for object identity instead of module name resolves the issue.
    leogama authored Apr 22, 2022
    Configuration menu
    Copy the full SHA
    44a9e54 View commit details
    Browse the repository at this point in the history

Commits on Apr 25, 2022

  1. Save objects imported with an alias and top level modules by referenc…

    …e in `dump_session(byref=TRUE)`
    
    Currently, `dump_session(byref=True)` misses some imported objects. For example:
    
    - If the session had a statement `import numpy as np`, it may find a reference to the `numpy` named
    as `np` in some internal module listed in `sys.resources`.  But if the module was imported with a
    non-canonical name, like `import numpy as nump`, it won't find it at all. Mapping the objects by id
    in `modmap` solves the issue.  Note that just types of objects usually imported under an alias must
    be looked up by id, otherwise common objects like singletons may be wrongly attributed to a module,
    and such reference in the module could change to a different object depending on its initialization
    and state.
    
    - If a object in the global scope is a top level module, like `math`, again `save_session` may find
    a reference to it in another module and it works. But if this module isn't referenced anywhere else,
    it won't be found because the function only looks for objects inside the `sys.resources` modules and
    not for the modules themselves.
    
    This commit introduces two new attributes to session modules saved by reference:
    - `__dill_imported_as`: a list with (module name, object name, object alias in session)
    - `__dill_imported_top_level`: a list with (module name, module alias in session)
    
    I did it this way for forwards (complete) and backwards (partial) compatibility.
    
    Oh, and I got rid of that nasty `exec()` call in `_restore_modules()`! ;)
    leogama committed Apr 25, 2022
    Configuration menu
    Copy the full SHA
    a252e44 View commit details
    Browse the repository at this point in the history

Commits on Apr 26, 2022

  1. Deal with top level functions with dump_session()

    Fixes RecursionWarning error where a function defined in the top level of the module being saved with
    `dump_session(byref=True)`, of which "globals" is a reference to the original module's `__dict__`,
    makes dill to try to save this instead of the modified module's `__dict__`, triggering recursion.
    leogama committed Apr 26, 2022
    Configuration menu
    Copy the full SHA
    8b15b99 View commit details
    Browse the repository at this point in the history

Commits on Apr 28, 2022

  1. Configuration menu
    Copy the full SHA
    47a060d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6156dc5 View commit details
    Browse the repository at this point in the history

Commits on Apr 29, 2022

  1. Configuration menu
    Copy the full SHA
    bf419f1 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1aef037 View commit details
    Browse the repository at this point in the history

Commits on Apr 30, 2022

  1. Configuration menu
    Copy the full SHA
    abdfd5c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a87496b View commit details
    Browse the repository at this point in the history
  3. dump_session(): more tests

    leogama committed Apr 30, 2022
    Configuration menu
    Copy the full SHA
    e4ba1e8 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    095b4cb View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d1450bf View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f292584 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    5b90579 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    1f310a9 View commit details
    Browse the repository at this point in the history

Commits on May 1, 2022

  1. Configuration menu
    Copy the full SHA
    3ae5f1a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0c1b1d1 View commit details
    Browse the repository at this point in the history