Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

close() an event loop while it is running #171

@GoogleCodeExporter

Description

@GoogleCodeExporter
It should not be possible to close an event loop while it is still running. I 
suggest to modify the close() method to raise an error if the loop is still 
running.

Subclasses of BaseEventLoop should call the parent close() method first, or 
they will modify their state while the loop will not be closed.

Example:

---
import asyncio

@asyncio.coroutine
def test(loop):
    print(repr(loop))
    loop.stop()
    print(repr(loop))
    loop.close()
    print(repr(loop))

loop = asyncio.get_event_loop()
loop.run_until_complete(test(loop))

---

Result (with the closed patch applied):

---
<_UnixSelectorEventLoop running=True closed=False debug=False>
<_UnixSelectorEventLoop running=True closed=False debug=False>
<_UnixSelectorEventLoop running=True closed=True debug=False>
Traceback (most recent call last):
  File "x.py", line 12, in <module>
    loop.run_until_complete(test(loop))
  File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 215, in run_until_complete
    self.run_forever()
  File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 195, in run_forever
    self._run_once()
  File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 822, in _run_once
    event_list = self._selector.select(timeout)
AttributeError: 'NoneType' object has no attribute 'select'

---

Original issue reported on code.google.com by victor.s...@gmail.com on 3 Jun 2014 at 11:00

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions