Skip to content

Commit e08df19

Browse files
committed
Add a unit test with the forkserver start method.
1 parent 64c7fae commit e08df19

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

Lib/test/test_profiling/test_tracing_profiler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ class Foo:
191191
f.close()
192192
assert_python_ok('-m', "cProfile", f.name)
193193

194-
def test_process_run_pickle(self):
195-
# gh-140729: test use Process in cProfile.
194+
def _test_process_run_pickle(self, start_method):
196195
val = 10
197196
with tempfile.NamedTemporaryFile("w+", delete_on_close=False) as f:
198197
f.write(textwrap.dedent(
@@ -204,7 +203,7 @@ def worker(x):
204203
exit(x ** 2)
205204
206205
if __name__ == "__main__":
207-
multiprocessing.set_start_method("spawn")
206+
multiprocessing.set_start_method('{start_method}')
208207
p = multiprocessing.Process(target=worker, args=({val},))
209208
p.start()
210209
p.join()
@@ -216,6 +215,14 @@ def worker(x):
216215
self.assertIn(bytes(f"exitcode = {val**2}", encoding='utf8'), out)
217216
self.assertNotIn(b"Can't pickle", err)
218217

218+
def test_process_spawn_pickle(self):
219+
# gh-140729: test use Process in cProfile.
220+
self._test_process_run_pickle('spawn')
221+
222+
def test_process_forkserver_pickle(self):
223+
# gh-140729: test use Process in cProfile.
224+
self._test_process_run_pickle('forkserver')
225+
219226

220227
def main():
221228
if '-r' not in sys.argv:
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Fix a pickling error in the ``cProfile`` module when profiling a script that
2-
uses :class:`multiprocessing.Process` with the ``spawn`` start method.
2+
uses :class:`multiprocessing.Process` with the ``spawn`` and ``forkserver``
3+
start methods.

0 commit comments

Comments
 (0)