Skip to content

Conversation

@YvesDup
Copy link
Contributor

@YvesDup YvesDup commented Feb 11, 2026

When profilng the ttt.py script via cProfile module ,

import multiprocessing

def worker_proc(x):
    return x ** 99

def main_proc():
    p = multiprocessing.Process(target=worker_proc, args=(10,))
    p.start()
    p.join()

if __name__ == "__main__":
    main_proc()
./python.exe -m cProfile ttt.py 

an error occurs:

AttributeError: module '__main__' has no attribute 'worker_proc'

This fix does not apply to the profile module, which is deprecated and will be removed in python 3.17.

@YvesDup YvesDup requested a review from pablogsal as a code owner February 11, 2026 16:44
def test_process_run_pickle(self):
# gh-140729: test use Process in cProfile.
val = 10
test_script = f'''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using textwrap.dedent to preserve the indentation, even though the other tests in this file don't do so:

        test_script = textwrap.dedent(f'''
        import multiprocess
        ....
        ''')

@@ -0,0 +1,2 @@
Fix pickling error in the cProfile module when using ``multiprocessing.Process``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix pickling error in the cProfile module when using ``multiprocessing.Process``
Fix pickling error in the :mode:`cProfile` module when using :class:`multiprocessing.Process`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants