File tree 3 files changed +31
-27
lines changed 3 files changed +31
-27
lines changed Original file line number Diff line number Diff line change 13
13
import threading
14
14
from test import support
15
15
from test .support import threading_helper
16
+ import warnings
16
17
17
18
18
19
LONGSLEEP = 2
@@ -63,19 +64,17 @@ def test_wait(self):
63
64
64
65
prefork_lives = self .alive .copy ()
65
66
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 5
5
from test .support import threading_helper
6
6
import _thread as thread
7
7
import time
8
+ import warnings
8
9
import weakref
9
10
10
11
from test import lock_tests
@@ -238,11 +239,13 @@ def test_forkinthread(self):
238
239
def fork_thread (read_fd , write_fd ):
239
240
nonlocal pid
240
241
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
246
249
247
250
# child process
248
251
try :
Original file line number Diff line number Diff line change @@ -604,13 +604,15 @@ def test_is_alive_after_fork(self):
604
604
for i in range (20 ):
605
605
t = threading .Thread (target = lambda : None )
606
606
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 ()
612
614
613
- support .wait_process (pid , exitcode = 10 )
615
+ support .wait_process (pid , exitcode = 10 )
614
616
615
617
def test_main_thread (self ):
616
618
main = threading .main_thread ()
You can’t perform that action at this time.
0 commit comments