Skip to content
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

Importing multiprocessing breaks _checkmodule in _pickle.c #120170

Open
li-dan opened this issue Jun 6, 2024 · 0 comments
Open

Importing multiprocessing breaks _checkmodule in _pickle.c #120170

li-dan opened this issue Jun 6, 2024 · 0 comments
Labels
topic-multiprocessing type-bug An unexpected behavior, bug, or error

Comments

@li-dan
Copy link

li-dan commented Jun 6, 2024

Bug report

Bug description:

#86572 describes a bug where importing multiprocessing causes pickle to determine the wrong module for objects without __module__. #23403 fixed the bug, but only for the pure Python implementation of pickle. The C extension module is still broken.

Consider a file foo.py containing:

def f():
    pass
del f.__module__

Then, in an interactive session:

>>> import multiprocessing
>>> from foo import f
>>> import pickle
>>> import pickletools
>>> pickletools.dis(pickle.dumps(f))
    0: \x80 PROTO      4
    2: \x95 FRAME      21
   11: \x8c SHORT_BINUNICODE '__mp_main__'
   24: \x94 MEMOIZE    (as 0)
   25: \x8c SHORT_BINUNICODE 'f'
   28: \x94 MEMOIZE    (as 1)
   29: \x93 STACK_GLOBAL
   30: \x94 MEMOIZE    (as 2)
   31: .    STOP
highest protocol among opcodes = 4
>>> pickletools.dis(pickle._dumps(f))
    0: \x80 PROTO      4
    2: \x95 FRAME      13
   11: \x8c SHORT_BINUNICODE 'foo'
   16: \x94 MEMOIZE    (as 0)
   17: \x8c SHORT_BINUNICODE 'f'
   20: \x94 MEMOIZE    (as 1)
   21: \x93 STACK_GLOBAL
   22: \x94 MEMOIZE    (as 2)
   23: .    STOP
highest protocol among opcodes = 4

pickle.dumps tries to import f from __mp_main__. pickle._dumps correctly determines that f comes from the foo module.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@li-dan li-dan added the type-bug An unexpected behavior, bug, or error label Jun 6, 2024
li-dan pushed a commit to li-dan/cpython that referenced this issue Jun 6, 2024
Importing multiprocessing adds an alias to __main__ named __mp_main__.
In python#23403, the Python version of whichmodule() was fixed to exclude
__mp_main__. Apply the same fix to the C version of the function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-multiprocessing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants