Skip to content

Commit

Permalink
Cancel input downloads if one of them fails
Browse files Browse the repository at this point in the history
  • Loading branch information
philandstuff committed Dec 20, 2024
1 parent f2ba468 commit 84acf65
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion python/cog/server/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,23 @@ def start_prediction() -> None:
self._input_download_pool.submit(item.convert) for item in v
]
to_await += futs[k]
futures.wait(to_await, return_when=futures.FIRST_EXCEPTION)
done, not_done = futures.wait(to_await, return_when=futures.FIRST_EXCEPTION)

if len(not_done) > 0:
# if any future isn't done, this is because one of the
# futures raised an exception. first we cancel outstanding
# work
for fut in not_done:
fut.cancel()
# then we find an exception to raise
for fut in done:
fut.result() # raises if the future finished with an exception
# we should never get here
raise Exception("Internal error: lost track of exception while downloading input files")

# all futures are done. some might still have raised an
# exception, but when we call fut.result() that will re-raise
# and do the right thing
for k, v in futs.items():
if isinstance(v, list):
payload[k] = []
Expand Down

0 comments on commit 84acf65

Please sign in to comment.