bpo-40275: Adding threading_helper submodule in test.support (GH-20263)

This commit is contained in:
Hai Shi 2020-05-28 06:10:27 +08:00 committed by GitHub
parent 7d80b35af1
commit e80697d687
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 483 additions and 428 deletions

View file

@ -2,6 +2,7 @@ import os
import unittest
import random
from test import support
from test.support import threading_helper
import _thread as thread
import time
import weakref
@ -32,8 +33,8 @@ class BasicThreadTest(unittest.TestCase):
self.running = 0
self.next_ident = 0
key = support.threading_setup()
self.addCleanup(support.threading_cleanup, *key)
key = threading_helper.threading_setup()
self.addCleanup(threading_helper.threading_cleanup, *key)
class ThreadRunningTests(BasicThreadTest):
@ -58,7 +59,7 @@ class ThreadRunningTests(BasicThreadTest):
self.done_mutex.release()
def test_starting_threads(self):
with support.wait_threads_exit():
with threading_helper.wait_threads_exit():
# Basic test for thread creation.
for i in range(NUMTASKS):
self.newtask()
@ -94,7 +95,7 @@ class ThreadRunningTests(BasicThreadTest):
verbose_print("trying stack_size = (%d)" % tss)
self.next_ident = 0
self.created = 0
with support.wait_threads_exit():
with threading_helper.wait_threads_exit():
for i in range(NUMTASKS):
self.newtask()
@ -116,7 +117,7 @@ class ThreadRunningTests(BasicThreadTest):
mut.acquire()
mut.release()
with support.wait_threads_exit():
with threading_helper.wait_threads_exit():
thread.start_new_thread(task, ())
while not started:
time.sleep(POLL_SLEEP)
@ -140,7 +141,7 @@ class ThreadRunningTests(BasicThreadTest):
started = thread.allocate_lock()
with support.catch_unraisable_exception() as cm:
with support.wait_threads_exit():
with threading_helper.wait_threads_exit():
started.acquire()
thread.start_new_thread(task, ())
started.acquire()
@ -180,7 +181,7 @@ class Barrier:
class BarrierTest(BasicThreadTest):
def test_barrier(self):
with support.wait_threads_exit():
with threading_helper.wait_threads_exit():
self.bar = Barrier(NUMTASKS)
self.running = NUMTASKS
for i in range(NUMTASKS):
@ -223,7 +224,7 @@ class TestForkInThread(unittest.TestCase):
self.read_fd, self.write_fd = os.pipe()
@unittest.skipUnless(hasattr(os, 'fork'), 'need os.fork')
@support.reap_threads
@threading_helper.reap_threads
def test_forkinthread(self):
pid = None
@ -243,7 +244,7 @@ class TestForkInThread(unittest.TestCase):
finally:
os._exit(0)
with support.wait_threads_exit():
with threading_helper.wait_threads_exit():
thread.start_new_thread(fork_thread, (self.read_fd, self.write_fd))
self.assertEqual(os.read(self.read_fd, 2), b"OK")
os.close(self.write_fd)