Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bb3938b
Initial commit
YvesDup Feb 11, 2026
0a7badb
📜🤖 Added by blurb_it.
blurb-it[bot] Feb 11, 2026
9ef3626
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Feb 11, 2026
b3ce881
Update Misc/NEWS.d/next/Library/2026-02-11-16-47-27.gh-issue-140729.2…
YvesDup Feb 15, 2026
e861c04
Fix nits in news file
YvesDup Feb 16, 2026
6805048
Fix nits
YvesDup Feb 17, 2026
d3ba649
Fix news file.
YvesDup Feb 17, 2026
aa2883b
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Feb 26, 2026
4bdb4a9
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Apr 5, 2026
273bdb9
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Jun 2, 2026
79d51cd
Fix nits in news file
YvesDup Jun 4, 2026
329b069
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Jun 17, 2026
7c5f2d3
Update from reviews
YvesDup Jun 18, 2026
e47555f
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Jun 18, 2026
c57719e
refactor test code
YvesDup Jun 18, 2026
0801a2b
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Jun 18, 2026
437dcd9
Cancel modifs to test_frozenmain.h
YvesDup Jun 19, 2026
64c7fae
Fix review comments for GH-144715
pablogsal Jul 1, 2026
e08df19
Add a unit test with the ``forkserver`` start method.
YvesDup Jul 2, 2026
bb7e87a
Merge branch 'main' into cprofile-module-multiprocessing-update
YvesDup Jul 2, 2026
a904f41
Do not run the test_process_forkserver_pickle test on Windows
YvesDup Jul 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/profiling/tracing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def main():
# in the module's namespace.
globs = module.__dict__
globs.update({
'__spec__': spec,
# Set __spec__ to None so the profiled program behaves like a
# script run directly (gh-140729).
'__spec__': None,
'__file__': spec.origin,
'__name__': spec.name,
'__package__': None,
Expand Down
35 changes: 34 additions & 1 deletion Lib/test/test_profiling/test_tracing_profiler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test suite for the cProfile module."""

import sys
import unittest

Expand Down Expand Up @@ -192,6 +191,40 @@ class Foo:
f.close()
assert_python_ok('-m', "cProfile", f.name)

def _test_process_run_pickle(self, start_method):
val = 10
with tempfile.NamedTemporaryFile("w+", delete_on_close=False) as f:
f.write(textwrap.dedent(
f'''\
import multiprocessing

def worker(x):
print(__name__)
exit(x ** 2)

if __name__ == "__main__":
multiprocessing.set_start_method('{start_method}')
p = multiprocessing.Process(target=worker, args=({val},))
p.start()
p.join()
print("p.exitcode =", p.exitcode)
'''))
f.close()
_, out, err = assert_python_ok('-m', "cProfile", f.name)
self.assertIn(b"__mp_main__", out)
self.assertIn(bytes(f"exitcode = {val**2}", encoding='utf8'), out)
self.assertNotIn(b"Can't pickle", err)

def test_process_spawn_pickle(self):
# gh-140729: test use Process in cProfile.
self._test_process_run_pickle('spawn')

@unittest.skipIf(sys.platform == 'win32',
"No 'forkserver' start method on Windows")
def test_process_forkserver_pickle(self):
# gh-140729: test use Process in cProfile.
self._test_process_run_pickle('forkserver')


def main():
if '-r' not in sys.argv:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a pickling error in the ``cProfile`` module when profiling a script that
uses :class:`multiprocessing.Process` with the ``spawn`` and ``forkserver``
start methods.
Loading