File tree Expand file tree Collapse file tree 3 files changed +31
-27
lines changed Expand file tree Collapse file tree 3 files changed +31
-27
lines changed Original file line number Diff line number Diff line change 1313import threading
1414from test import support
1515from test .support import threading_helper
16+ import warnings
1617
1718
1819LONGSLEEP = 2
@@ -63,19 +64,17 @@ def test_wait(self):
6364
6465 prefork_lives = self .alive .copy ()
6566
66- if sys .platform in ['unixware7' ]:
67- cpid = os .fork1 ()
68- else :
69- cpid = os .fork ()
70-
71- if cpid == 0 :
72- # Child
73- time .sleep (LONGSLEEP )
74- n = 0
75- for key in self .alive :
76- if self .alive [key ] != prefork_lives [key ]:
77- n += 1
78- os ._exit (n )
79- else :
80- # Parent
81- self .wait_impl (cpid , exitcode = 0 )
67+ # Ignore the warning about fork with threads.
68+ with warnings .catch_warnings (category = DeprecationWarning ,
69+ action = "ignore" ):
70+ if (cpid := os .fork ()) == 0 :
71+ # Child
72+ time .sleep (LONGSLEEP )
73+ n = 0
74+ for key in self .alive :
75+ if self .alive [key ] != prefork_lives [key ]:
76+ n += 1
77+ os ._exit (n )
78+ else :
79+ # Parent
80+ self .wait_impl (cpid , exitcode = 0 )
Original file line number Diff line number Diff line change 55from test .support import threading_helper
66import _thread as thread
77import time
8+ import warnings
89import weakref
910
1011from test import lock_tests
@@ -238,11 +239,13 @@ def test_forkinthread(self):
238239 def fork_thread (read_fd , write_fd ):
239240 nonlocal pid
240241
241- # fork in a thread
242- pid = os .fork ()
243- if pid :
244- # parent process
245- return
242+ # Ignore the warning about fork with threads.
243+ with warnings .catch_warnings (category = DeprecationWarning ,
244+ action = "ignore" ):
245+ # fork in a thread (DANGER, undefined per POSIX)
246+ if (pid := os .fork ()):
247+ # parent process
248+ return
246249
247250 # child process
248251 try :
Original file line number Diff line number Diff line change @@ -604,13 +604,15 @@ def test_is_alive_after_fork(self):
604604 for i in range (20 ):
605605 t = threading .Thread (target = lambda : None )
606606 t .start ()
607- pid = os .fork ()
608- if pid == 0 :
609- os ._exit (11 if t .is_alive () else 10 )
610- else :
611- t .join ()
607+ # Ignore the warning about fork with threads.
608+ with warnings .catch_warnings (category = DeprecationWarning ,
609+ action = "ignore" ):
610+ if (pid := os .fork ()) == 0 :
611+ os ._exit (11 if t .is_alive () else 10 )
612+ else :
613+ t .join ()
612614
613- support .wait_process (pid , exitcode = 10 )
615+ support .wait_process (pid , exitcode = 10 )
614616
615617 def test_main_thread (self ):
616618 main = threading .main_thread ()
You can’t perform that action at this time.
0 commit comments