Skip to content

Commit

Permalink
Fixed rare case where tasks could get stuck starting forever
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Dec 3, 2014
1 parent 6c7666b commit a87fb38
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Trakttv.bundle/Contents/Code/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,31 @@ def wait(self):
if not self.started:
return False

# Wait for the task to finish
if not self.complete:
# Wait for lock
self.lock.acquire()

if self.exception:
raise self.exception
# Release it again
self.lock.release()

if self.exception or not self.complete:
return None

return self.result

def run(self):
# Wait for lock
self.lock.acquire()

# Ensure task hasn't already been started
if self.started:
return

self.lock.acquire()
self.started = True

try:
# Call task
self.result = self.target(*self.args, **self.kwargs)
except CancelException, e:
self.exception = e
Expand All @@ -57,6 +66,8 @@ def run(self):
log.warn('Exception raised in triggered function %s (%s) %s: %s' % (
self.target, type(e), e, traceback.format_exc()
))
finally:
# Release lock
self.complete = True
self.lock.release()

self.complete = True
self.lock.release()

0 comments on commit a87fb38

Please sign in to comment.