Skip to content

Commit

Permalink
fixup! tumblr_backup: Implement wget module
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cebtenzzre committed Oct 20, 2020
1 parent a54eec4 commit d0005e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions tumblr_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -212,6 +222,7 @@ def _do_wait(self):
except:
with self.cond:
self.flag = None # Waiting never completed
self.cond.notify_all()
raise

@staticmethod
Expand Down

0 comments on commit d0005e4

Please sign in to comment.