Skip to content

Commit 38ff6ff

Browse files
CPython developersyouknowone
CPython developers
authored andcommitted
Update thread/threading from CPython 3.10.5
1 parent 7917d12 commit 38ff6ff

File tree

5 files changed

+669
-139
lines changed

5 files changed

+669
-139
lines changed

Lib/test/test_thread.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def task():
133133
del task
134134
while not done:
135135
time.sleep(POLL_SLEEP)
136+
support.gc_collect() # For PyPy or other GCs.
136137
self.assertEqual(thread._count(), orig)
137138

138139
def test_unraisable_exception(self):
@@ -227,30 +228,31 @@ def setUp(self):
227228
@unittest.skipUnless(hasattr(os, 'fork'), 'need os.fork')
228229
@threading_helper.reap_threads
229230
def test_forkinthread(self):
230-
status = "not set"
231+
pid = None
231232

232-
def thread1():
233-
nonlocal status
233+
def fork_thread(read_fd, write_fd):
234+
nonlocal pid
234235

235236
# fork in a thread
236237
pid = os.fork()
237-
if pid == 0:
238-
# child
239-
try:
240-
os.close(self.read_fd)
241-
os.write(self.write_fd, b"OK")
242-
finally:
243-
os._exit(0)
244-
else:
245-
# parent
246-
os.close(self.write_fd)
247-
pid, status = os.waitpid(pid, 0)
238+
if pid:
239+
# parent process
240+
return
241+
242+
# child process
243+
try:
244+
os.close(read_fd)
245+
os.write(write_fd, b"OK")
246+
finally:
247+
os._exit(0)
248248

249249
with threading_helper.wait_threads_exit():
250-
thread.start_new_thread(thread1, ())
251-
self.assertEqual(os.read(self.read_fd, 2), b"OK",
252-
"Unable to fork() in thread")
253-
self.assertEqual(status, 0)
250+
thread.start_new_thread(fork_thread, (self.read_fd, self.write_fd))
251+
self.assertEqual(os.read(self.read_fd, 2), b"OK")
252+
os.close(self.write_fd)
253+
254+
self.assertIsNotNone(pid)
255+
support.wait_process(pid, exitcode=0)
254256

255257
def tearDown(self):
256258
try:

Lib/test/test_threadedtempfile.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import unittest
2020
import io
2121
import threading
22-
import sys
2322
from traceback import print_exc
2423

2524

0 commit comments

Comments
 (0)