Skip to content

Commit a91a4d1

Browse files
committed
silence the warning in more tests.
1 parent 0ca9fc7 commit a91a4d1

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

Lib/test/fork_wait.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import threading
1414
from test import support
1515
from test.support import threading_helper
16+
import warnings
1617

1718

1819
LONGSLEEP = 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)

Lib/test/test_thread.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from test.support import threading_helper
66
import _thread as thread
77
import time
8+
import warnings
89
import weakref
910

1011
from 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:

Lib/test/test_threading.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)