Skip to content

Commit 95bbd21

Browse files
pjonssonomad
authored andcommitted
generate: fix pool for pytest-cov
Fix this now that I saw it since this stuff is tricky to diagnose the root cause of once things are suddenly not shutting down as they should.
1 parent b6ec61a commit 95bbd21

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cubedash/generate.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,19 @@ def on_complete(
199199
for p in products:
200200
on_complete(*generate_report((p.name, settings, grouping_time_zone)))
201201
else:
202-
with multiprocessing.Pool(workers) as pool:
203-
summary: TimePeriodOverview | None
202+
# Shut down pool nicely to keep pytest-cov happy.
203+
# https://pytest-cov.readthedocs.io/en/latest/subprocess-support.html#if-you-use-multiprocessing-pool
204+
pool = multiprocessing.Pool(workers)
205+
try:
204206
for product_name, result, summary in pool.imap_unordered(
205207
generate_report,
206208
((p.name, settings, grouping_time_zone) for p in products),
207209
chunksize=1,
208210
):
209211
on_complete(product_name, result, summary)
210-
211-
pool.close()
212-
pool.join()
212+
finally:
213+
pool.close()
214+
pool.join()
213215

214216
status_messages = ", ".join(
215217
f"{count_} {status.name.lower()}" for status, count_ in counts.items()

0 commit comments

Comments
 (0)