-
Notifications
You must be signed in to change notification settings - Fork 184
CLN drop Cloudpickler's globals_ref attribute #229
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #229 +/- ##
==========================================
- Coverage 84.92% 84.81% -0.11%
==========================================
Files 1 1
Lines 577 573 -4
Branches 114 113 -1
==========================================
- Hits 490 486 -4
Misses 63 63
Partials 24 24
Continue to review full report at Codecov.
|
|
Hum, this is fishy. I wonder if we did not break something that was not tested in the past when doing this series of changes in the handling of base globals. Maybe this is related to @suquark's comment #216 (comment) but I am not sure I understand. |
|
In summary:
Prior to the series of changes (i.e before commit 9a52ba3)
My opinion is that I made two tests that I ran using a version of CloudPickle, with HEAD at a249c44 def test_global_variable_sharing_same_cloudpickler(self):
code_template = """
from cloudpickle import loads, dumps
A_SHARED_GLOBAL = 1
def f():
global A_SHARED_GLOBAL
A_SHARED_GLOBAL += 1
return A_SHARED_GLOBAL
def g():
global A_SHARED_GLOBAL
return A_SHARED_GLOBAL
# the depickled functions share a global variable, as the the globals
# dict will be shared in the cloudpickler's memo
cloned_f, cloned_g = loads(dumps([f, g]))
del A_SHARED_GLOBAL
UNPICKLED_SHARED_GLOBAL = cloned_f()
assert UNPICKLED_SHARED_GLOBAL == 2, UNPICKLED_SHARED_GLOBAL
assert cloned_g() == UNPICKLED_SHARED_GLOBAL, cloned_g()
"""
assert_run_python_script(textwrap.dedent(code_template))
def test_global_variable_sharing_different_cloudpickler(self):
code_template = """
from cloudpickle import loads, dumps
A_SHARED_GLOBAL = 1
def f():
global A_SHARED_GLOBAL
A_SHARED_GLOBAL += 1
return A_SHARED_GLOBAL
def g():
global A_SHARED_GLOBAL
return A_SHARED_GLOBAL
# here, the two functions do not share the global variables, as they
# are picked in different pickle strings, so the memo is not use to
# pickle the globals dictionnary
cloned_f = loads(dumps(f))
cloned_g = loads(dumps(g))
del A_SHARED_GLOBAL
UNPICKLED_SHARED_GLOBAL = cloned_f()
assert UNPICKLED_SHARED_GLOBAL == 2, UNPICKLED_SHARED_GLOBAL
# this fails, so the global variable is not shared
assert cloned_g() == UNPICKLED_SHARED_GLOBAL, cloned_g()
"""
assert_run_python_script(textwrap.dedent(code_template))the first one pass, the second one fails. If modifying the code by removing globals_ref: @@ -260,7 +260,7 @@ class CloudPickler(Pickler):
# set of modules to unpickle
self.modules = set()
# map ids to dictionary. used to ensure that functions can share global env
- self.globals_ref = {}
+ # self.globals_ref = {}
def dump(self, obj):
self.inject_addons()
@@ -632,8 +632,9 @@ class CloudPickler(Pickler):
# save the dict
dct = func.__dict__
- base_globals = self.globals_ref.get(id(func.__globals__), {})
- self.globals_ref[id(func.__globals__)] = base_globals
+ # base_globals = self.globals_ref.get(id(func.__globals__), {})
+ # self.globals_ref[id(func.__globals__)] = base_globals
+ base_globals = {}
return (code, f_globals, defaults, closure, dct, base_globals)the two tests fail. After the series of changes (i.e on master)The situation has changed: I think one of the key takeaways of my endeavours is that |
|
Perhaps this is related to my issues at #230? |
|
@TheButlah so far, all the code I posted here was ran on a Linux machine, so I cannot see a clear relation between this and #230. I did not investigate your issue though, and I am sadly not familiar with windows specificities. |
|
I believe we actually want to preserve this. This is now being correctly tested as part of: #240. Let's close this issue. |
Not sure
globals_refis still needed, now thatbase_globalsis simply the function's module name.