-
Notifications
You must be signed in to change notification settings - Fork 167
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
Support persistent function.__globals__ #411
base: master
Are you sure you want to change the base?
Support persistent function.__globals__ #411
Conversation
686b224
to
5477bd7
Compare
5477bd7
to
bbe76e9
Compare
Codecov Report
@@ Coverage Diff @@
## master #411 +/- ##
==========================================
+ Coverage 91.61% 91.66% +0.05%
==========================================
Files 3 3
Lines 656 660 +4
Branches 135 137 +2
==========================================
+ Hits 601 605 +4
Misses 34 34
Partials 21 21
Continue to review full report at Codecov.
|
Error: Unable to process command '::add-path::nightly-venv/bin' successfully. 214 Error: The `add-path` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
Hi, thank you for the PR. If I understood correctly, this feature allows for a pickled function's Could you provide more context on the use case for which you would need this feature? Additional contextWe did some back and forth in the past in
We explored globals reconcilication as an opt-in feature in #216, but ended up not merging it. |
Our cloud-hosted jupyter is a serverless solution, which uses lazy-loading |
(credits to @faucct - cloudpipe#411)
Bump |
A quick search on (Implementing There is a risk that the changes in this PR might break code relying on such subclasses , since @ogrisel if you have any thoughts on this, I'm happy to hear them :) |
I have meant that this won’t break anything for people who don’t intentionally save globals in persistent_id. For those who do this change is more like a fix. The link you’ve shared gives persistent ids to custom classes, not to dict, so this change does not affect them: |
Agreed.
I don't quite agree with that for now, you would need to elaborate about why this is a fix for anyone using
That is true. The example I linked is made to highlight the fact that there exists some code chunks out there -either open source, surely other closed source- consisting of a There are two ways I see this PR moving forward (other than me being wrong, in this case, feel free to explain why):
|
Here is why I think of this change as a fix. The docs say that
If users customize
Same logic applies to custom
|
To me, this seems like a bit of an abuse of the protocol for Here the use case seems to be more how to customize the pickling of dynamically defined functions. To achieve this goal, I would instead recommend to override the I agree that this private API, an is not guaranteed to be stable when upgrading the version of cloudpickle though. |
I don't think of this as an abuse of the protocol for |
Mmh, does that problem actually exist on |
I've meant that we will define |
@faucct, I have an idea that may solve your use-case: f_globals['__cloudpickle_globals'] = True You can then detect and handle such dictionaries using your own |
I don't understand this sentence. If you customize |
You have said that this is a private API here:
|
Will we have to add this key to user |
For you to be able to distinguish between different f_globals['__cloudpickle_globals_id'] = id(func.__globals__) In my opinion, such a change solves your use case as well as the current PR. Morevoer, this change does not rely on some code branching depending on the return value of
Given the current code in your PR, I'm assuming your application already contains some code able to detect |
I think that the |
We could also subclass dict with a custom class that would hold this link to the original globals dict, possibly as a weak ref and we could implement the reducer to rebuild a regular dict instead at unpickling time. Actually it does not even need to be subclass a dict or hold a weakref. |
I have stopped understanding the solutions you suggest. :( Could you adapt the example from description to them, please? |
Actually I don't think it would work since the original The problem is that to implement the use case correctly with the |
I am working on a prototype to make things clearer. |
@faucct @pierreglaser feel free to have a look at: #430. |
Support
Pickler#persistent_id
andUnpickler#persistent_load
for__globals__
of functions: