Skip to content

Commit bc3751e

Browse files
committed
Attempt to make the unit test more robust and clean up process management
resources.
1 parent 8e2b573 commit bc3751e

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

Lib/test/test_concurrent_futures/executor.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,23 @@ def test_shutdown_notifies_cancelled_futures(self):
238238
# gh-136655: ensure cancelled futures are notified
239239
count = self.worker_count * 2
240240
barrier = self.create_barrier(self.worker_count + 1)
241-
fs = [self.executor.submit(blocking_raiser,
242-
barrier if index < self.worker_count else None)
243-
for index in range(count)]
244-
245-
self.executor.shutdown(wait=False, cancel_futures=True)
246-
try:
247-
barrier.wait()
248-
except threading.BrokenBarrierError:
249-
pass
250-
251-
for future in fs:
252-
self.assertRaises(
253-
(FalseyBoolException, futures.CancelledError, threading.BrokenBarrierError),
254-
future.result)
255-
256-
self.assertIn('CANCELLED_AND_NOTIFIED', [f._state for f in fs])
241+
with self.executor as exec:
242+
fs = [exec.submit(blocking_raiser,
243+
barrier if index < self.worker_count else None)
244+
for index in range(count)]
245+
246+
exec.shutdown(wait=False, cancel_futures=True)
247+
try:
248+
barrier.wait()
249+
except threading.BrokenBarrierError:
250+
pass
251+
252+
for future in fs:
253+
self.assertRaises(
254+
(FalseyBoolException, futures.CancelledError, threading.BrokenBarrierError),
255+
future.result)
256+
257+
self.assertIn('CANCELLED_AND_NOTIFIED', [f._state for f in fs])
257258

258259
def blocking_raiser(barrier=None):
259260
if barrier is not None:

0 commit comments

Comments
 (0)