From d0005e46e9c6fa041c0fca7a359896fc22ba1c31 Mon Sep 17 00:00:00 2001 From: Cebtenzzre Date: Tue, 20 Oct 2020 17:34:44 -0400 Subject: [PATCH] fixup! tumblr_backup: Implement wget module Avoid a deadlock in ThreadPool.cancel with a new function: WaitOnMainThread.destroy, which prevents blocking in signal() when we're trying to stop the thread --- tumblr_backup.py | 1 + util.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/tumblr_backup.py b/tumblr_backup.py index 6bdf3a1..41039b0 100755 --- a/tumblr_backup.py +++ b/tumblr_backup.py @@ -1414,6 +1414,7 @@ def wait(self): def cancel(self): self.abort.set() + no_internet.destroy() for i, t in enumerate(self.threads, start=1): log.status('Stopping threads {}{}\r'.format(' ' * i, '.' * (len(self.threads) - i))) t.join() diff --git a/util.py b/util.py index e5eae8d..3786038 100644 --- a/util.py +++ b/util.py @@ -202,6 +202,16 @@ def check(self): self.flag = False self.cond.notify_all() + # Call on main thread to prevent threads from blocking in signal() + def destroy(self): + assert self.cond is not None + if self.flag is None: + return + + with self.cond: + self.flag = None # Cause all waiters to exit + self.cond.notify_all() + def _do_wait(self): assert self.cond is not None if self.flag is None: @@ -212,6 +222,7 @@ def _do_wait(self): except: with self.cond: self.flag = None # Waiting never completed + self.cond.notify_all() raise @staticmethod