[Mod] Promise:增加对traceback的支持
This commit is contained in:
parent
f3f2598c44
commit
7e56c3fd49
@ -7,6 +7,7 @@ from enum import Enum
|
||||
class PromiseResultType(Enum):
|
||||
Result = 1
|
||||
Exception = 2
|
||||
Traceback = 3
|
||||
|
||||
|
||||
class Promise(object):
|
||||
@ -24,7 +25,14 @@ class Promise(object):
|
||||
res = self._queue.get(timeout=timeout)
|
||||
if res[0] == PromiseResultType.Result:
|
||||
return res[1]
|
||||
raise res[1]
|
||||
elif res[0] == PromiseResultType.Exception:
|
||||
raise res[1]
|
||||
else:
|
||||
et, ev, tb = res[1]
|
||||
raise et, ev, tb
|
||||
|
||||
def set_exception(self, val):
|
||||
self._queue.put((PromiseResultType.Exception, val))
|
||||
def set_exception(self, valueOrType, val=None, tb=None):
|
||||
if val is None:
|
||||
self._queue.put((PromiseResultType.Exception, val))
|
||||
else:
|
||||
self._queue.put((PromiseResultType.Traceback, (valueOrType, val, tb)))
|
||||
|
Loading…
Reference in New Issue
Block a user