From 9db347efee3a804598f6f2b7e56b1c21012bc18c Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Sun, 19 Jan 2014 18:37:56 +0100 Subject: [PATCH] Propagate error during async operation properly --- tv.boxeeplay.svtplay3/async_task.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tv.boxeeplay.svtplay3/async_task.py b/tv.boxeeplay.svtplay3/async_task.py index b168020..d74555e 100644 --- a/tv.boxeeplay.svtplay3/async_task.py +++ b/tv.boxeeplay.svtplay3/async_task.py @@ -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):