Update test_threading with a couple changes from trunk that got lost due, I

presume, to merge conflicts.
This commit is contained in:
Jeffrey Yasskin 2008-03-29 05:06:52 +00:00
parent 34465e7ec6
commit ca67412f28

View file

@ -32,7 +32,8 @@ def __init__(self, name, testcase, sema, mutex, nrunning):
def run(self):
delay = random.random() / 10000.0
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.mutex:
@ -49,7 +50,7 @@ def run(self):
self.testcase.assert_(self.nrunning.get() >= 0)
if verbose:
print('%s is finished. %d tasks are running' %
self.getName(), self.nrunning.get())
(self.getName(), self.nrunning.get()))
class ThreadTests(unittest.TestCase):
@ -242,7 +243,10 @@ def test_enumerate_after_join(self):
enum = threading.enumerate
old_interval = sys.getcheckinterval()
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.start()
t.join()