Skip to content

Reloading a session into the same module keeps the previous session  #498

@svartkanin

Description

@svartkanin

I'm generating 2 session dumps with

import dill
a = 1234
dill.dump_session('test1.session')

and

import dill
b = 1234
dill.dump_session('test2.session')

Then loading them back into a module sequentially

import types
import dill

mod = types.ModuleType('test')
print(mod.__dict__.get('a', None))
print(mod.__dict__.get('b', None))

dill.load_session('test1.session', main=mod)
print(mod.__dict__.get('a', None))
print(mod.__dict__.get('b', None))


mod = types.ModuleType('test')
print(mod.__dict__.get('a', None))
print(mod.__dict__.get('b', None))

dill.load_session('test2.session', main=mod)
print(mod.__dict__.get('a', None))
print(mod.__dict__.get('b', None))

I get the following output

None   # a
None   # b
1234   # a
None   # b
None   # a
None   # b
1234   # a
1234   # b

Before the second session file is read, it clearly shows that the mod variable has no a nor b set. But then when reading in the test2.session file it suddenly sets both a and b. But only b was actually dumped into that file.

Is this an expected behavior?
I'd have expected that after the test2.session was loaded, only the b variable to be present

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