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

@YvesDupYvesDup commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

When profilng the ttt.py script via cProfile module ,

importmultiprocessingdefworker_proc(x):
returnx**99defmain_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.

Comment threadLib/test/test_profiling/test_sampling_profiler/test_advanced.py Outdated
Comment threadMisc/NEWS.d/next/Library/2026-02-11-16-47-27.gh-issue-140729.2uTPQp.rst Outdated
@github-actions

Copy link
Copy Markdown

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

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label May 6, 2026
@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label Jun 2, 2026
Comment threadMisc/NEWS.d/next/Library/2026-02-11-16-47-27.gh-issue-140729.2uTPQp.rst Outdated
Comment threadLib/test/test_profiling/test_sampling_profiler/test_advanced.py Outdated
+ Move unittest
+ Update news file
+ run make regen-configure
Comment threadLib/test/test_profiling/test_tracing_profiler.py Outdated
@YvesDup

Copy link
Copy Markdown
ContributorAuthor

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

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

@aiskaisk 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
ContributorAuthor

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

@pablogsalpablogsal 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!

@pablogsalpablogsal 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:mainJul 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

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-appbedevere-appBot 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
@YvesDup

Copy link
Copy Markdown
ContributorAuthor

Because the cProfile migration, I think the backport should only affect version 3.15.

@bedevere-app

Copy link
Copy Markdown

GH-153265 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Jul 7, 2026
@aisk

aisk commented Jul 7, 2026

Copy link
Copy Markdown
Member

The cProfile migration just moves the file to another location, so I found that we can backport it to 3.14 easily. The result is above.

But while trying to backport this to 3.13, I found that because #132738 was not backported to 3.13 and it changed the surrounding code, we can't simply backport the current PR.

Since 3.13 will reach end of life in around two months, I think we can just leave it as it is.

@aiskaisk removed the needs backport to 3.13 bugs and security fixes label Jul 7, 2026
Sign up for freeto 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.

3 participants

@YvesDup@pablogsal@aisk