Skip to content

Commit

Permalink
[contacts._progress._progressbardict2thread.handle_kb_interrupt] rais…
Browse files Browse the repository at this point in the history
…e KeyboardInterrupt when interrupting
  • Loading branch information
gph82 committed Jul 12, 2024
1 parent 5a9851e commit 1f17f47
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mdciao/contacts/_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ def _progressbardict2thread(progressbar_dict, sleep_between_updates=1, overwrite
An event that can be used
as flag for when to stop updating
"""
# Prepare threading
exit_event = _threading.Event()
def handle_kb_interrupt(sig, frame):
exit_event.set()
_signal.signal(_signal.SIGINT, handle_kb_interrupt)

if _is_notebook():
widg_len = max([len(bar) + 5 for bar in progressbar_dict["pbars"]])
Expand Down Expand Up @@ -218,6 +213,14 @@ def work(progress): # arg is just for compat
_print_w_option_to_overwrite(progressbar_dict["pbars"], overwrite=overwrite)
thread = _threading.Thread(target=work, args=(progress,))

exit_event = _threading.Event()
def handle_kb_interrupt(sig, frame):
exit_event.set()
thread.join()
raise KeyboardInterrupt

_signal.signal(_signal.SIGINT, handle_kb_interrupt)

return thread, exit_event

def _print_w_option_to_overwrite(lines, overwrite=False):
Expand Down

0 comments on commit 1f17f47

Please sign in to comment.