Send exceptions across CoroutinePool.wait

This commit is contained in:
donovan
2008-06-03 11:32:22 -07:00
parent e3c6528772
commit 5d2a4b54c4

View File

@@ -44,6 +44,11 @@ class Cancelled(RuntimeError):
pass
class ExceptionWrapper(object):
def __init__(self, e):
self.e = e
NOT_USED = object()
@@ -311,6 +316,13 @@ class CoroutinePool(pools.Pool):
traceback.print_exc()
if evt is not None:
evt.send(exc=e)
if self._tracked_events is not None:
if self._next_event is None:
self._tracked_events.append(ExceptionWrapper(e))
else:
ne = self._next_event
self._next_event = None
ne.send(exc=e)
def _execute(self, evt, func, args, kw):
""" Private implementation of the execute methods.
@@ -384,6 +396,9 @@ class CoroutinePool(pools.Pool):
return self._next_event.wait()
result = self._tracked_events.pop(0)
if isinstance(result, ExceptionWrapper):
raise result.e
if not self._tracked_events:
self._next_event = event()
return result