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

modified dynamic module globals get overriden at load time #199

Closed
pierreglaser opened this issue Sep 7, 2018 · 1 comment
Closed

modified dynamic module globals get overriden at load time #199

pierreglaser opened this issue Sep 7, 2018 · 1 comment

Comments

@pierreglaser
Copy link
Member

Hi all,
While introspecting test_dynamic_module for #192, I wrote a script that

  • dumps a dynamic module,
  • changes a global variable inside
  • finally re-load the dumped module.
import imp
import cloudpickle
import textwrap
import sys
import pickle

mod = imp.new_module('mod')
code = '''
x = 1
'''
exec(textwrap.dedent(code), mod.__dict__)

# first, dump the module
fileobj = cloudpickle.dumps(mod)

# change the mod's global variable x
mod.x = 2

# create child-process-like process environnement where
# mod is already loaded with the modified variable x
sys.modules['mod'] = mod

# finally, re-load the dynamic module
mod2 = pickle.loads(fileobj)

# this fails for now
assert mod2.x == mod.x

The modified global variable gets overriden. I wonder if this is global behavior, or it needs to be changed.

Using Python 3.7.0, cloudpickle==0.5.5

@ogrisel
Copy link
Contributor

ogrisel commented Oct 1, 2018

This was fixed in #205.

@ogrisel ogrisel closed this as completed Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants