Skip to content

gh-140729: Fix the cProfile module when the executed script contains calls to multiprocessing.Process#144715

Open
YvesDup wants to merge 12 commits into
python:mainfrom
YvesDup:cprofile-module-multiprocessing-update
Open

gh-140729: Fix the cProfile module when the executed script contains calls to multiprocessing.Process#144715
YvesDup wants to merge 12 commits into
python:mainfrom
YvesDup:cprofile-module-multiprocessing-update

Conversation

@YvesDup

@YvesDup YvesDup commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

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
Comment thread Lib/test/test_profiling/test_sampling_profiler/test_advanced.py
Comment thread Misc/NEWS.d/next/Library/2026-02-11-16-47-27.gh-issue-140729.2uTPQp.rst Outdated
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 6, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 2, 2026
@@ -0,0 +1 @@
Fix pickling error in the ``cProfile`` module when using :class:`multiprocessing.Process` in script, which can not be properly pickled and executed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like there is a missing newline, which caused the CI to fail.

@requires_remote_subprocess_debugging()
class TestProcessRunSupport(unittest.TestCase):
"""
Test that Process works correctly with cProfile.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test case for cProfile should be located in test_tracing_profiler.py rather than under test_sampling_profiler/. And the @requires_remote_subprocess_debugging() is also not required for cProfile cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will move the test quickly

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