-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Shared namespaces #534
base: master
Are you sure you want to change the base?
Shared namespaces #534
Conversation
I remember why I didn't do this earlier. It makes |
6221041
to
7fe9bb5
Compare
When this is ready, either mark it as ready for review, or request a review. |
This is the GitHub workflow we kind of discovered and have being using:
(If you didn't open the PR in draft mode, you may still convert it to a draft.)
I'll take a (deeper) look at this later today. Edit: a brief look at the changes made me think that:
|
@anivegesana I read your changes more thoroughly and couldn't find any problem relative About conflicts with the other PR, I'll have to solve it there. |
@mmckerns and @anivegesana: I'm thinking of ways to reorganize and simplify the segment of Lines 1825 to 1871 in 7fe9bb5
|
Just test if |
I've opened a PR in your fork: anivegesana#2 |
# we only care about session the first pass thru | ||
pickler._first_pass = False | ||
StockPickler.save_dict(pickler, obj) | ||
|
||
# IMPORTANT: update the following code whenever save_dict is changed in pickle.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that the code for save_dict
in all supported version of python are is the same (at least from if pickler.bin
to pickler.memoize(obj)
). The idea here is to insert the code with __name__
to save_dict
while not yielding control to the StockPickler
, correct? It seems that save_dict
hasn't changed as far back as at least 3.1, so I'm not worried about the copy being made here.
dill/tests/_globals_dummy.py
Outdated
@@ -0,0 +1,10 @@ | |||
# This file is used by test_shared_globals in test_functions.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be possible to use or modify a simple test like test_functors
so that file is used as opposed to using an additional file like this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me. I'll do some testing and also have to understand what concerns @leogama has with your solution aside from there's some intersection with code in some of his PRs. Then I can move this to approve/request.
EDIT: Appears to correct behavior seen in #532, however doesn't seem to affect code initiating #466. Also fails the test case presented in #536:
from statistics import mean
pickle_loaded = dill.dumps(mean)
del sys.modules['statistics']
pickle_unloaded = dill.dumps(mean)
assert 'statistics' not in sys.modules #FAIL
Ok, apparently there's some conceptual difference on what the correct solution is... so this appears to need some thought. I'll dig into #536 before coming back to this.
Reorganize and simplify if-else clauses in `save_function()`
I will need to look into this again at some point since it was a while that I looked at this before and forgot what these PRs were for. If I remember correctly, @leogama's changes were supposed to update the PRs to work with the code on master. |
I'll fix anything tomorrow night. It is late.Ok. I think that was the only additional case I needed to fix.
This PR caches global dictionary copies when pickling functions. The caching allows for the preservation of a globals dictionary shared between multiple functions. If the global dictionary is pickled, it will be pickled as the copy in all future references to prevent duplication of the globals dictionary.
Fixes #532, fixes #466