summaryrefslogtreecommitdiff
path: root/Lib/asyncio/events.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-02-18 18:02:19 -0500
committerYury Selivanov <yselivanov@sprymix.com>2014-02-18 18:02:19 -0500
commit569efa2e4bf985f27a9f85393e29d3ad8ac73344 (patch)
tree892c07e1a7b02669d13331bd991f3a72078ba03d /Lib/asyncio/events.py
parent6acc5e1330239cd721205b310dfddec1eb6425c1 (diff)
downloadcpython-git-569efa2e4bf985f27a9f85393e29d3ad8ac73344.tar.gz
asyncio: New error handling API. Issue #20681.
Diffstat (limited to 'Lib/asyncio/events.py')
-rw-r--r--Lib/asyncio/events.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 7841ad9ba5..f61c5b7487 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -19,10 +19,11 @@ from .log import logger
class Handle:
"""Object returned by callback registration methods."""
- __slots__ = ['_callback', '_args', '_cancelled']
+ __slots__ = ['_callback', '_args', '_cancelled', '_loop']
- def __init__(self, callback, args):
+ def __init__(self, callback, args, loop):
assert not isinstance(callback, Handle), 'A Handle is not a callback'
+ self._loop = loop
self._callback = callback
self._args = args
self._cancelled = False
@@ -39,9 +40,14 @@ class Handle:
def _run(self):
try:
self._callback(*self._args)
- except Exception:
- logger.exception('Exception in callback %s %r',
- self._callback, self._args)
+ except Exception as exc:
+ msg = 'Exception in callback {}{!r}'.format(self._callback,
+ self._args)
+ self._loop.call_exception_handler({
+ 'message': msg,
+ 'exception': exc,
+ 'handle': self,
+ })
self = None # Needed to break cycles when an exception occurs.
@@ -50,9 +56,9 @@ class TimerHandle(Handle):
__slots__ = ['_when']
- def __init__(self, when, callback, args):
+ def __init__(self, when, callback, args, loop):
assert when is not None
- super().__init__(callback, args)
+ super().__init__(callback, args, loop)
self._when = when
@@ -328,6 +334,17 @@ class AbstractEventLoop:
def remove_signal_handler(self, sig):
raise NotImplementedError
+ # Error handlers.
+
+ def set_exception_handler(self, handler):
+ raise NotImplementedError
+
+ def default_exception_handler(self, context):
+ raise NotImplementedError
+
+ def call_exception_handler(self, context):
+ raise NotImplementedError
+
class AbstractEventLoopPolicy:
"""Abstract policy for accessing the event loop."""