diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2014-02-18 18:02:19 -0500 |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2014-02-18 18:02:19 -0500 |
commit | 569efa2e4bf985f27a9f85393e29d3ad8ac73344 (patch) | |
tree | 892c07e1a7b02669d13331bd991f3a72078ba03d /Lib/asyncio/futures.py | |
parent | 6acc5e1330239cd721205b310dfddec1eb6425c1 (diff) | |
download | cpython-git-569efa2e4bf985f27a9f85393e29d3ad8ac73344.tar.gz |
asyncio: New error handling API. Issue #20681.
Diffstat (limited to 'Lib/asyncio/futures.py')
-rw-r--r-- | Lib/asyncio/futures.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py index d09f423ce4..b9cd45c786 100644 --- a/Lib/asyncio/futures.py +++ b/Lib/asyncio/futures.py @@ -83,9 +83,10 @@ class _TracebackLogger: in a discussion about closing files when they are collected. """ - __slots__ = ['exc', 'tb'] + __slots__ = ['exc', 'tb', 'loop'] - def __init__(self, exc): + def __init__(self, exc, loop): + self.loop = loop self.exc = exc self.tb = None @@ -102,8 +103,11 @@ class _TracebackLogger: def __del__(self): if self.tb: - logger.error('Future/Task exception was never retrieved:\n%s', - ''.join(self.tb)) + msg = 'Future/Task exception was never retrieved:\n{tb}' + context = { + 'message': msg.format(tb=''.join(self.tb)), + } + self.loop.call_exception_handler(context) class Future: @@ -173,8 +177,12 @@ class Future: # has consumed the exception return exc = self._exception - logger.error('Future/Task exception was never retrieved:', - exc_info=(exc.__class__, exc, exc.__traceback__)) + context = { + 'message': 'Future/Task exception was never retrieved', + 'exception': exc, + 'future': self, + } + self._loop.call_exception_handler(context) def cancel(self): """Cancel the future and schedule callbacks. @@ -309,7 +317,7 @@ class Future: if _PY34: self._log_traceback = True else: - self._tb_logger = _TracebackLogger(exception) + self._tb_logger = _TracebackLogger(exception, self._loop) # Arrange for the logger to be activated after all callbacks # have had a chance to call result() or exception(). self._loop.call_soon(self._tb_logger.activate) |