summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-16 17:45:51 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-01-16 17:45:51 +0100
commit59f9d6021eeb4817181c8aa9f6a9b795c6f5660d (patch)
tree3d986f7d2dc24f76f1134e90cb8374a5fbd34efd
parent4d108a6bcf3e529b61141026029034cc61a9f1de (diff)
downloadtrollius-59f9d6021eeb4817181c8aa9f6a9b795c6f5660d.tar.gz
Enhance BaseProactorEventLoop._loop_self_reading()
* Handle correctly CancelledError: just exit * On error, log the exception and exit Don't try to close the event loop, it is probably running and so it cannot be closed.
-rw-r--r--asyncio/proactor_events.py12
-rw-r--r--tests/test_proactor_events.py5
2 files changed, 12 insertions, 5 deletions
diff --git a/asyncio/proactor_events.py b/asyncio/proactor_events.py
index 6d8641f..ed17062 100644
--- a/asyncio/proactor_events.py
+++ b/asyncio/proactor_events.py
@@ -463,9 +463,15 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
if f is not None:
f.result() # may raise
f = self._proactor.recv(self._ssock, 4096)
- except:
- self.close()
- raise
+ except futures.CancelledError:
+ # _close_self_pipe() has been called, stop waiting for data
+ return
+ except Exception as exc:
+ self.call_exception_handler({
+ 'message': 'Error on reading from the event loop self pipe',
+ 'exception': exc,
+ 'loop': self,
+ })
else:
self._self_reading_future = f
f.add_done_callback(self._loop_self_reading)
diff --git a/tests/test_proactor_events.py b/tests/test_proactor_events.py
index dee147e..33a8a67 100644
--- a/tests/test_proactor_events.py
+++ b/tests/test_proactor_events.py
@@ -523,9 +523,10 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
def test_loop_self_reading_exception(self):
self.loop.close = mock.Mock()
+ self.loop.call_exception_handler = mock.Mock()
self.proactor.recv.side_effect = OSError()
- self.assertRaises(OSError, self.loop._loop_self_reading)
- self.assertTrue(self.loop.close.called)
+ self.loop._loop_self_reading()
+ self.assertTrue(self.loop.call_exception_handler.called)
def test_write_to_self(self):
self.loop._write_to_self()