mirror of
https://github.com/python/cpython.git
synced 2025-11-11 02:52:04 +00:00
Update test_threading with a couple changes from trunk that got lost due, I
presume, to merge conflicts.
This commit is contained in:
parent
34465e7ec6
commit
ca67412f28
1 changed files with 7 additions and 3 deletions
|
|
@ -32,7 +32,8 @@ def __init__(self, name, testcase, sema, mutex, nrunning):
|
||||||
def run(self):
|
def run(self):
|
||||||
delay = random.random() / 10000.0
|
delay = random.random() / 10000.0
|
||||||
if verbose:
|
if verbose:
|
||||||
print('task', self.getName(), 'will run for', delay, 'sec')
|
print('task %s will run for %.1f usec' %
|
||||||
|
(self.getName(), delay * 1e6))
|
||||||
|
|
||||||
with self.sema:
|
with self.sema:
|
||||||
with self.mutex:
|
with self.mutex:
|
||||||
|
|
@ -49,7 +50,7 @@ def run(self):
|
||||||
self.testcase.assert_(self.nrunning.get() >= 0)
|
self.testcase.assert_(self.nrunning.get() >= 0)
|
||||||
if verbose:
|
if verbose:
|
||||||
print('%s is finished. %d tasks are running' %
|
print('%s is finished. %d tasks are running' %
|
||||||
self.getName(), self.nrunning.get())
|
(self.getName(), self.nrunning.get()))
|
||||||
|
|
||||||
class ThreadTests(unittest.TestCase):
|
class ThreadTests(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -242,7 +243,10 @@ def test_enumerate_after_join(self):
|
||||||
enum = threading.enumerate
|
enum = threading.enumerate
|
||||||
old_interval = sys.getcheckinterval()
|
old_interval = sys.getcheckinterval()
|
||||||
try:
|
try:
|
||||||
for i in range(1, 1000):
|
for i in range(1, 100):
|
||||||
|
# Try a couple times at each thread-switching interval
|
||||||
|
# to get more interleavings.
|
||||||
|
sys.setcheckinterval(i // 5)
|
||||||
t = threading.Thread(target=lambda: None)
|
t = threading.Thread(target=lambda: None)
|
||||||
t.start()
|
t.start()
|
||||||
t.join()
|
t.join()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue