Skip to content

Commit d1935cd

Browse files
authored
[test] Use context manager for multiprocessing.Pool. NFC (#25159)
1 parent d73a7a1 commit d1935cd

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

test/parallel_testsuite.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ def run(self, result):
9797
use_cores = cap_max_workers_in_pool(min(self.max_cores, len(tests), num_cores()))
9898
print('Using %s parallel test processes' % use_cores, file=sys.stderr)
9999
with multiprocessing.Manager() as manager:
100-
pool = multiprocessing.Pool(use_cores)
101-
if python_multiprocessing_structures_are_buggy():
102-
failfast_event = progress_counter = lock = None
103-
else:
104-
failfast_event = manager.Event() if self.failfast else None
105-
progress_counter = manager.Value('i', 0)
106-
lock = manager.Lock()
107-
results = [pool.apply_async(run_test, (t, failfast_event, lock, progress_counter, len(tests))) for t in tests]
108-
results = [r.get() for r in results]
109-
results = [r for r in results if r is not None]
100+
with multiprocessing.Pool(use_cores) as pool:
101+
if python_multiprocessing_structures_are_buggy():
102+
failfast_event = progress_counter = lock = None
103+
else:
104+
failfast_event = manager.Event() if self.failfast else None
105+
progress_counter = manager.Value('i', 0)
106+
lock = manager.Lock()
107+
results = [pool.apply_async(run_test, (t, failfast_event, lock, progress_counter, len(tests))) for t in tests]
108+
results = [r.get() for r in results]
109+
results = [r for r in results if r is not None]
110110

111111
if self.failing_and_slow_first:
112112
previous_test_run_results = common.load_previous_test_run_results()
@@ -130,8 +130,7 @@ def update_test_results_to(test_name):
130130
update_test_results_to(r.test_name.split(' ')[0])
131131

132132
json.dump(previous_test_run_results, open(common.PREVIOUS_TEST_RUN_RESULTS_FILE, 'w'), indent=2)
133-
pool.close()
134-
pool.join()
133+
135134
return self.combine_results(result, results)
136135

137136
def reversed_tests(self):

0 commit comments

Comments
 (0)