-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-34572: change _pickle unpickling to use import rather than retrieving from sys.modules #9047
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
Changes from all commits
e47c5e1
595bdbb
f72802a
fa5dbeb
64a7f95
202d4e2
a0425ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fix C implementation of pickle.loads to use importlib's locking | ||
mechanisms, and thereby avoid using partially-loaded modules. | ||
Patch by Tim Burgess. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6623,13 +6623,13 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self, | |
} | ||
} | ||
|
||
module = PyImport_GetModule(module_name); | ||
/* | ||
* we don't use PyImport_GetModule here, because it can return partially- | ||
* initialised modules, which then cause the getattribute to fail. | ||
*/ | ||
module = PyImport_Import(module_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you benchmark how slower this is compared with just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. git master:
This PR:
So this is a sizable performance drop, but on a micro-benchmark. I don't think this will be significant in real-world cases. Usually, pickle performance becomes important when large pieces of data are serialized, and by construction you don't get many cc'ing @pierreglaser @ogrisel out of curiosity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1. Also,
pitrou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (module == NULL) { | ||
if (PyErr_Occurred()) | ||
return NULL; | ||
module = PyImport_Import(module_name); | ||
if (module == NULL) | ||
return NULL; | ||
return NULL; | ||
} | ||
global = getattribute(module, global_name, self->proto >= 4); | ||
Py_DECREF(module); | ||
|
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.
This is a neat test :-)