@@ -485,9 +485,7 @@ def test_is_alive_after_fork(self):
485
485
else :
486
486
t .join ()
487
487
488
- pid , status = os .waitpid (pid , 0 )
489
- self .assertTrue (os .WIFEXITED (status ))
490
- self .assertEqual (10 , os .WEXITSTATUS (status ))
488
+ support .wait_process (pid , exitcode = 10 )
491
489
492
490
def test_main_thread (self ):
493
491
main = threading .main_thread ()
@@ -507,6 +505,7 @@ def f():
507
505
def test_main_thread_after_fork (self ):
508
506
code = """if 1:
509
507
import os, threading
508
+ from test import support
510
509
511
510
pid = os.fork()
512
511
if pid == 0:
@@ -515,7 +514,7 @@ def test_main_thread_after_fork(self):
515
514
print(main.ident == threading.current_thread().ident)
516
515
print(main.ident == threading.get_ident())
517
516
else:
518
- os.waitpid (pid, 0)
517
+ support.wait_process (pid, exitcode= 0)
519
518
"""
520
519
_ , out , err = assert_python_ok ("-c" , code )
521
520
data = out .decode ().replace ('\r ' , '' )
@@ -528,6 +527,7 @@ def test_main_thread_after_fork(self):
528
527
def test_main_thread_after_fork_from_nonmain_thread (self ):
529
528
code = """if 1:
530
529
import os, threading, sys
530
+ from test import support
531
531
532
532
def f():
533
533
pid = os.fork()
@@ -540,7 +540,7 @@ def f():
540
540
# we have to flush before exit.
541
541
sys.stdout.flush()
542
542
else:
543
- os.waitpid (pid, 0)
543
+ support.wait_process (pid, exitcode= 0)
544
544
545
545
th = threading.Thread(target=f)
546
546
th.start()
@@ -813,11 +813,15 @@ def test_1_join_on_shutdown(self):
813
813
def test_2_join_in_forked_process (self ):
814
814
# Like the test above, but from a forked interpreter
815
815
script = """if 1:
816
+ from test import support
817
+
816
818
childpid = os.fork()
817
819
if childpid != 0:
818
- os.waitpid(childpid, 0)
820
+ # parent process
821
+ support.wait_process(childpid, exitcode=0)
819
822
sys.exit(0)
820
823
824
+ # child process
821
825
t = threading.Thread(target=joiningfunc,
822
826
args=(threading.current_thread(),))
823
827
t.start()
@@ -832,13 +836,17 @@ def test_3_join_in_forked_from_thread(self):
832
836
# In the forked process, the main Thread object must be marked as stopped.
833
837
834
838
script = """if 1:
839
+ from test import support
840
+
835
841
main_thread = threading.current_thread()
836
842
def worker():
837
843
childpid = os.fork()
838
844
if childpid != 0:
839
- os.waitpid(childpid, 0)
845
+ # parent process
846
+ support.wait_process(childpid, exitcode=0)
840
847
sys.exit(0)
841
848
849
+ # child process
842
850
t = threading.Thread(target=joiningfunc,
843
851
args=(main_thread,))
844
852
print('end of main')
@@ -901,9 +909,9 @@ def do_fork_and_wait():
901
909
# just fork a child process and wait it
902
910
pid = os .fork ()
903
911
if pid > 0 :
904
- os . waitpid (pid , 0 )
912
+ support . wait_process (pid , exitcode = 50 )
905
913
else :
906
- os ._exit (0 )
914
+ os ._exit (50 )
907
915
908
916
# start a bunch of threads that will fork() child processes
909
917
threads = []
@@ -930,12 +938,11 @@ def test_clear_threads_states_after_fork(self):
930
938
if pid == 0 :
931
939
# check that threads states have been cleared
932
940
if len (sys ._current_frames ()) == 1 :
933
- os ._exit (0 )
941
+ os ._exit (51 )
934
942
else :
935
- os ._exit (1 )
943
+ os ._exit (52 )
936
944
else :
937
- _ , status = os .waitpid (pid , 0 )
938
- self .assertEqual (0 , status )
945
+ support .wait_process (pid , exitcode = 51 )
939
946
940
947
for t in threads :
941
948
t .join ()
0 commit comments