X Tutup
Skip to content

Commit 606c3f5

Browse files
committed
Issue python#12041: Make test_wait3 more robust.
1 parent 5aa878c commit 606c3f5

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Lib/test/fork_wait.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def wait_impl(self, cpid):
4343
self.assertEqual(spid, cpid)
4444
self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
4545

46+
@support.reap_threads
4647
def test_wait(self):
4748
for i in range(NUM_THREADS):
4849
_thread.start_new(self.f, (i,))
@@ -69,7 +70,8 @@ def test_wait(self):
6970
os._exit(n)
7071
else:
7172
# Parent
72-
self.wait_impl(cpid)
73-
# Tell threads to die
74-
self.stop = 1
75-
time.sleep(2*SHORTSLEEP) # Wait for threads to die
73+
try:
74+
self.wait_impl(cpid)
75+
finally:
76+
# Tell threads to die
77+
self.stop = 1

Lib/test/test_wait3.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919

2020
class Wait3Test(ForkWait):
2121
def wait_impl(self, cpid):
22-
for i in range(10):
22+
# This many iterations can be required, since some previously run
23+
# tests (e.g. test_ctypes) could have spawned a lot of children
24+
# very quickly.
25+
for i in range(30):
2326
# wait3() shouldn't hang, but some of the buildbots seem to hang
2427
# in the forking tests. This is an attempt to fix the problem.
2528
spid, status, rusage = os.wait3(os.WNOHANG)
2629
if spid == cpid:
2730
break
28-
time.sleep(1.0)
31+
time.sleep(0.1)
2932

3033
self.assertEqual(spid, cpid)
3134
self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ Extension Modules
619619
Tests
620620
-----
621621

622+
- Issue #12041: Make test_wait3 more robust.
623+
622624
- Issue #11873: Change regex in test_compileall to fix occasional failures when
623625
when the randomly generated temporary path happened to match the regex.
624626

0 commit comments

Comments
 (0)
X Tutup