Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions problemtools/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ def submit_background_work(self, job: Callable[_P, _T], *args: _P.args, **kwargs
assert self.executor
self._background_work.append(self.executor.submit(job, *args, **kwargs))

def cancel_background_work(self) -> None:
for future in self._background_work:
future.cancel()

def wait_for_background_work(self) -> None:
concurrent.futures.wait(self._background_work)
5 changes: 5 additions & 0 deletions problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,11 @@ def check(self, context: Context) -> tuple[int, int]:
item.check(context)
except VerifyError:
pass
except KeyboardInterrupt:
# In multithreaded runs, we can queue up large chunks of work. If the
# user presses ctrl-c, we want to cancel that to exit quickly.
context.cancel_background_work()
raise
finally:
# Wait for background work to finish before performing an rmtree on
# the directory tree it uses.
Expand Down