Skip to content

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

Merged
pablogsal merged 21 commits into
python:mainfrom
YvesDup:cprofile-module-multiprocessing-update
Jul 6, 2026
Merged

gh-140729: Fix the cProfile module when the executed script contains calls to multiprocessing.Process#144715
pablogsal merged 21 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 Outdated
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
Comment thread Misc/NEWS.d/next/Library/2026-02-11-16-47-27.gh-issue-140729.2uTPQp.rst Outdated
Comment thread Lib/test/test_profiling/test_sampling_profiler/test_advanced.py Outdated
+ Move unittest
+ Update news file
+ run make regen-configure
Comment thread Lib/test/test_profiling/test_tracing_profiler.py Outdated
@YvesDup

YvesDup commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@aisk Could you help me about the failing test please ?

@YvesDup YvesDup requested a review from aisk June 19, 2026 08:58

@aisk aisk left a comment

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.

Thank you for the PR, LGTM!

@pablogsal

Copy link
Copy Markdown
Member

I pushed a small fix for this. Can you take a look?

@YvesDup

YvesDup commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I pushed a small fix for this. Can you take a look?

I agree with the comment in _init__.py file, really more explicit.

The fix also works with the forkserverstart method. I suggest to add a dedicated test with this start method, and update the news file. Do you agree ?

EDIT: I pushed a new commit including all the forkserver start method modifications

@pablogsal pablogsal left a comment

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.

LGTm thanks for the fix!

@pablogsal pablogsal added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 6, 2026
@pablogsal pablogsal merged commit d7275d3 into python:main Jul 6, 2026
61 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @YvesDup for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @YvesDup and @pablogsal, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker d7275d356916f839dc96aaa43a75e0bbde25732e 3.14

@bedevere-app

bedevere-app Bot commented Jul 6, 2026

Copy link
Copy Markdown

GH-153243 is a backport of this pull request to the 3.15 branch.

@miss-islington-app

Copy link
Copy Markdown

Sorry, @YvesDup and @pablogsal, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker d7275d356916f839dc96aaa43a75e0bbde25732e 3.13

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 6, 2026
pablogsal pushed a commit that referenced this pull request Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants