diff --git a/src/cosmic_ray/distribution/http.py b/src/cosmic_ray/distribution/http.py index 37f825ea..64f885d0 100644 --- a/src/cosmic_ray/distribution/http.py +++ b/src/cosmic_ray/distribution/http.py @@ -72,6 +72,7 @@ async def handle_completed_task(task): for work_item in pending_work: # Wait for an available URL while not urls: + assert fetchers.keys() done, pending = await asyncio.wait(fetchers.keys(), return_when=asyncio.FIRST_COMPLETED) for task in done: await handle_completed_task(task) @@ -84,9 +85,10 @@ async def handle_completed_task(task): fetchers[fetcher] = url, work_item.job_id # Drain the remaining work - done, pending = await asyncio.wait(fetchers.keys(), return_when=asyncio.ALL_COMPLETED) - for task in done: - await handle_completed_task(task) + if fetchers.keys(): + done, pending = await asyncio.wait(fetchers.keys(), return_when=asyncio.ALL_COMPLETED) + for task in done: + await handle_completed_task(task) async def send_request(url, work_item: WorkItem, test_command, timeout):