File tree Expand file tree Collapse file tree 1 file changed +28
-20
lines changed Expand file tree Collapse file tree 1 file changed +28
-20
lines changed Original file line number Diff line number Diff line change 2020import signal
2121import textwrap
2222import traceback
23+ import warnings
2324
2425from unittest import mock
2526from test import lock_tests
@@ -1183,15 +1184,18 @@ def do_fork_and_wait():
11831184 else :
11841185 os ._exit (50 )
11851186
1186- # start a bunch of threads that will fork() child processes
1187- threads = []
1188- for i in range (16 ):
1189- t = threading .Thread (target = do_fork_and_wait )
1190- threads .append (t )
1191- t .start ()
1187+ # Ignore the warning about fork with threads.
1188+ with warnings .catch_warnings (category = DeprecationWarning ,
1189+ action = "ignore" ):
1190+ # start a bunch of threads that will fork() child processes
1191+ threads = []
1192+ for i in range (16 ):
1193+ t = threading .Thread (target = do_fork_and_wait )
1194+ threads .append (t )
1195+ t .start ()
11921196
1193- for t in threads :
1194- t .join ()
1197+ for t in threads :
1198+ t .join ()
11951199
11961200 @support .requires_fork ()
11971201 def test_clear_threads_states_after_fork (self ):
@@ -1204,18 +1208,22 @@ def test_clear_threads_states_after_fork(self):
12041208 threads .append (t )
12051209 t .start ()
12061210
1207- pid = os .fork ()
1208- if pid == 0 :
1209- # check that threads states have been cleared
1210- if len (sys ._current_frames ()) == 1 :
1211- os ._exit (51 )
1212- else :
1213- os ._exit (52 )
1214- else :
1215- support .wait_process (pid , exitcode = 51 )
1216-
1217- for t in threads :
1218- t .join ()
1211+ try :
1212+ # Ignore the warning about fork with threads.
1213+ with warnings .catch_warnings (category = DeprecationWarning ,
1214+ action = "ignore" ):
1215+ pid = os .fork ()
1216+ if pid == 0 :
1217+ # check that threads states have been cleared
1218+ if len (sys ._current_frames ()) == 1 :
1219+ os ._exit (51 )
1220+ else :
1221+ os ._exit (52 )
1222+ else :
1223+ support .wait_process (pid , exitcode = 51 )
1224+ finally :
1225+ for t in threads :
1226+ t .join ()
12191227
12201228
12211229class SubinterpThreadingTests (BaseTestCase ):
You can’t perform that action at this time.
0 commit comments