diff --git a/slic/core/task/task.py b/slic/core/task/task.py index ddf3788c6..a990992e4 100644 --- a/slic/core/task/task.py +++ b/slic/core/task/task.py @@ -38,7 +38,13 @@ class Task(BaseTask): return self.wait() def wait(self): - self.thread.join() + try: + staggered_join(self.thread) + except KeyboardInterrupt: + print() # print new line after ^C + if self.stopper: + self.stopper() + self.thread.join() #TODO: should this timeout? if self.exception: raise TaskError from self.exception return self.result @@ -64,3 +70,12 @@ class TaskError(RuntimeError): +def staggered_join(thread, timeout=1): + """ + Continuously join for timeout seconds to not block KeyboardInterrupt + """ + while thread.is_alive(): + thread.join(timeout) + + +