@@ -234,3 +234,50 @@ def worker(x):
234234
235235 self .assertIn ("Results: [2, 4, 6]" , stdout )
236236 self .assertNotIn ("Can't pickle" , stderr )
237+
238+
239+ @requires_remote_subprocess_debugging ()
240+ class TestProcessRunSupport (unittest .TestCase ):
241+ """
242+ Test that Process works correctly with cProfile.
243+ """
244+
245+ def test_process_run_pickle (self ):
246+ # gh-140729: test use Process in cProfile.
247+ val = 10
248+ test_script = f'''
249+ import multiprocessing
250+
251+ def worker(x):
252+ print(__name__)
253+ exit(x ** 2)
254+
255+ if __name__ == "__main__":
256+ multiprocessing.set_start_method("spawn")
257+ p = multiprocessing.Process(target=worker, args=({ val } ,))
258+ p.start()
259+ p.join()
260+ print("p.exitcode =", p.exitcode)
261+ '''
262+
263+ with os_helper .temp_dir () as temp_dir :
264+ script = script_helper .make_script (
265+ temp_dir , 'test_process_run_pickle' , test_script
266+ )
267+ with SuppressCrashReport ():
268+ with script_helper .spawn_python (
269+ "-m" , "cProfile" ,
270+ script ,
271+ stdout = subprocess .PIPE ,
272+ stderr = subprocess .PIPE ,
273+ text = True
274+ ) as proc :
275+ try :
276+ stdout , stderr = proc .communicate (timeout = SHORT_TIMEOUT )
277+ except subprocess .TimeoutExpired :
278+ proc .kill ()
279+ stdout , stderr = proc .communicate ()
280+
281+ self .assertIn ("__mp_main__" , stdout )
282+ self .assertIn (f"exitcode = { val ** 2 } " , stdout )
283+ self .assertNotIn ("Can't pickle" , stderr )
0 commit comments