Portable mode: first draft (Brace yourselves) #491
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This draft is a proof of concept. It is the first complete version of a "portable mode" implementation.
The pickle streams generated by it have the following design:
-> Bootstrap header that contains:
--> Op-codes to create
dill
anddill._dill
empty modules--> Minimal logic to check if a
dill
module can be imported and its version--> The "payload", a compressed pickle stream that is loaded conditionally and contains:
---> A first batch of bootstrapped constructors:
_create_code
,_create_function
,_import_module
and_reverse_typemap
---> A second batch of constructors loaded using the constructors from the first batch, with its global vars, etc.
-> Body: the standard pickle stream generated by
Pickler.dump
Design considerations:
Pickler.dump
, directly to the file-like object, and have to leave the unpickling stack empty when loaded.cPickle
in the future, the header can't use memoization as the memo mapping ofcPickle
is private (it can just be copied afterwards).This is what drove me to use an internal pickle stream (the "payload") instead of putting everything directly in the header:
dill._dill
can be implemented as unpickling the payload or an empty pickle streamNote 1: The code annotation is incomplete and outdated. I may complete it in the next days.
Note 2: Don't mind the changes made for testing purposes, they were just a quick and dirty way to test the portable mode with a variety of objects.
PS: It's a monster, I know.