Skip to content

Commit

Permalink
Propagate error during async operation properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Pehrson committed Jan 19, 2014
1 parent 13d2aec commit 9db347e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tv.boxeeplay.svtplay3/async_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ def __init__(self, target, args=(), kwargs={}):
self.kwargs = kwargs
self.setDaemon(True)
self.returned = None
self.error = None
self.exc_info = None

def run(self):
try:
self.returned = self.target(*self.args, **self.kwargs)
except Exception, e:
self.error = e
except Exception:
import sys
self.exc_info= sys.exc_info()

def get_result(self):
if self.isAlive():
raise RuntimeError("Not finished yet")
if self.error is not None:
raise AsyncError("Error occurred while doing background work", self.error)
if self.exc_info:
raise self.exc_info[1], None, self.exc_info[2]
return self.returned

class AsyncError(Exception):
Expand Down

0 comments on commit 9db347e

Please sign in to comment.