diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-11-23 10:54:21 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-11-23 10:54:21 +0100 |
commit | 75f79b477e2da91d805dc138ae5f8f6d9e507da5 (patch) | |
tree | 772c505fa51a11352cbfe16657f1e20199be221c | |
parent | a8bf7d14fd5855bebc450b8e6fddce48e20d5989 (diff) | |
download | aioeventlet-75f79b477e2da91d805dc138ae5f8f6d9e507da5.tar.gz |
fix call_soon() when called on a closed loop
-rw-r--r-- | aiogreen.py | 4 | ||||
-rw-r--r-- | tests/test_callback.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/aiogreen.py b/aiogreen.py index 45b4ac4..79d005f 100644 --- a/aiogreen.py +++ b/aiogreen.py @@ -209,7 +209,7 @@ class EventLoop(asyncio.SelectorEventLoop): def call_soon(self, callback, *args): handle = super(EventLoop, self).call_soon(callback, *args) - if self._selector._event: + if self._selector is not None and self._selector._event: # selector.select() is running: write into the self-pipe to wake up # the selector self._write_to_self() @@ -217,7 +217,7 @@ class EventLoop(asyncio.SelectorEventLoop): def call_at(self, when, callback, *args): handle = super(EventLoop, self).call_at(when, callback, *args) - if self._selector._event: + if self._selector is not None and self._selector._event: # selector.select() is running: write into the self-pipe to wake up # the selector self._write_to_self() diff --git a/tests/test_callback.py b/tests/test_callback.py index 58f787b..fb29528 100644 --- a/tests/test_callback.py +++ b/tests/test_callback.py @@ -32,6 +32,16 @@ class CallbackTests(tests.TestCase): self.loop.run_forever() self.assertEqual(result, ["Hello", "World"]) + def test_close_soon(self): + def func(): + pass + + self.loop.close() + # FIXME: calling call_soon() on a closed event loop should raise an + # exception: + # http://bugs.python.org/issue22922 + self.loop.call_soon(func) + if __name__ == '__main__': import unittest |