mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #21326: Add a new is_closed() method to asyncio.BaseEventLoop
Add BaseEventLoop._closed attribute and use it to check if the event loop was closed or not, instead of checking different attributes in each subclass of BaseEventLoop. run_forever() and run_until_complete() methods now raise a RuntimeError('Event loop is closed') exception if the event loop was closed. BaseProactorEventLoop.close() now also cancels "accept futures".
This commit is contained in:
parent
15386652bf
commit
bb2fc5b2a5
7 changed files with 80 additions and 19 deletions
|
@ -52,6 +52,20 @@ class BaseEventLoopTests(unittest.TestCase):
|
|||
gen = self.loop._make_subprocess_transport(m, m, m, m, m, m, m)
|
||||
self.assertRaises(NotImplementedError, next, iter(gen))
|
||||
|
||||
def test_close(self):
|
||||
self.assertFalse(self.loop.is_closed())
|
||||
self.loop.close()
|
||||
self.assertTrue(self.loop.is_closed())
|
||||
|
||||
# it should be possible to call close() more than once
|
||||
self.loop.close()
|
||||
self.loop.close()
|
||||
|
||||
# operation blocked when the loop is closed
|
||||
f = asyncio.Future(loop=self.loop)
|
||||
self.assertRaises(RuntimeError, self.loop.run_forever)
|
||||
self.assertRaises(RuntimeError, self.loop.run_until_complete, f)
|
||||
|
||||
def test__add_callback_handle(self):
|
||||
h = asyncio.Handle(lambda: False, (), self.loop)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue