This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients gvanrossum, mark.dickinson
Date 2014-04-22.08:12:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1398154363.0.0.853788262895.issue21326@psf.upfronthosting.co.za>
In-reply-to
Content
In the new asyncio library, it's easy for newbies (like me) to accidentally try to run a coroutine on a closed event loop.  Doing so leads to a rather inscrutable exception and traceback:

>>> loop.run_until_complete(compute())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 203, in run_until_complete
    self.run_forever()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 184, in run_forever
    self._run_once()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 778, in _run_once
    event_list = self._selector.select(timeout)
AttributeError: 'NoneType' object has no attribute 'select'

Is it possible to replace this with something clearer?  For example, something like: RuntimeError("Can't schedule coroutine on closed event loop.")


Here's the full code snippet:


Python 3.4.0 (default, Mar 25 2014, 11:07:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> @asyncio.coroutine
... def compute():
...     print("Starting computation")
...     yield from asyncio.sleep(2.0)
...     print("Complete")
... 
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(compute())
Starting computation
Complete
>>> loop.close()  # whoops
>>> # some time later
... 
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(compute())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 203, in run_until_complete
    self.run_forever()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 184, in run_forever
    self._run_once()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 778, in _run_once
    event_list = self._selector.select(timeout)
AttributeError: 'NoneType' object has no attribute 'select'
History
Date User Action Args
2014-04-22 08:12:43mark.dickinsonsetrecipients: + mark.dickinson, gvanrossum
2014-04-22 08:12:42mark.dickinsonsetmessageid: <1398154363.0.0.853788262895.issue21326@psf.upfronthosting.co.za>
2014-04-22 08:12:42mark.dickinsonlinkissue21326 messages
2014-04-22 08:12:42mark.dickinsoncreate