8000 gh-120170: Exclude __mp_main__ in C version of whichmodule() by li-dan · Pull Request #120171 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-120170: Exclude __mp_main__ in C version of whichmodule() #120171

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

Merged
merged 2 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-120170: Exclude __mp_main__ in C version of whichmodule()
Importing multiprocessing adds an alias to __main__ named __mp_main__.
In #23403, the Python version of whichmodule() was fixed to exclude
__mp_main__. Apply the same fix to the C version of the function.
  • Loading branch information
li-dan committed Jan 29, 2025
commit 4b99d39bc45be50af8a4e3bdd77816597a5bf0f7
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix an issue in the :mod:`!_pickle` extension module in which importing
:mod:`multiprocessing` could change how pickle identifies which module an
object belongs to, potentially breaking the unpickling of those objects.
4 changes: 4 additions & 0 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,10 @@ _checkmodule(PyObject *module_name, PyObject *module,
_PyUnicode_EqualToASCIIString(module_name, "__main__")) {
return -1;
}
if (PyUnicode_Check(module_name) &&
_PyUnicode_EqualToASCIIString(module_name, "__mp_main__")) {
return -1;
}

PyObject *candidate = get_deep_attribute(module, dotted_path, NULL);
if (candidate == NULL) {
Expand Down
Loading
0