Title: Event loop implementation docs advertise set_event_loop which doesn't work with
Type: Stage:
Components: asyncio, Documentation Versions: Python 3.9, Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Cilyan Olowen, asvetlov, docs@python, hniksic, yselivanov
Priority: normal Keywords:

Created on 2019-10-09 17:14 by hniksic, last changed 2020-01-27 15:18 by Cilyan Olowen.

Messages (4)
msg354288 - (view) Author: Hrvoje Nikšić (hniksic) * Date: 2019-10-09 17:14
The docs of SelectorEventLoop and ProactorEventLoop contain examples that call asyncio.set_event_loop:

      selector = selectors.SelectSelector()
      loop = asyncio.SelectorEventLoop(selector)

But this won't have any effect on code that uses, because creates a fresh event loop. Since is the recommended way to execute async code and is used consistently throughout the documentation, this might be confusing to someone who tries to e.g. use the proactor loop on Windows.

I propose the following:

* add a disclaimer that instantiating the event loop won't affect calls to, and that loop.run_until_complete() must be used; and

* link to asyncio.set_event_loop_policy(), which does work with, but doesn't allow fine-tuning the details, such as which selector to use for the SelectorEventLoop.
msg354289 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2019-10-09 17:36
Yes, docs updates sound good.
msg360770 - (view) Author: Cilyan Olowen (Cilyan Olowen) Date: 2020-01-27 15:07
It doesn't seem to work either for asyncio.get_event_loop, especially when using asyncio.wait(), the loop complains that 

"RuntimeError: Task <Task pending coro=<Event.wait() running at lib\asyncio\> cb=[_wait.<locals>._on_completion() at lib\asyncio\]> got Future <Future pending> attached to a different loop"
msg360772 - (view) Author: Cilyan Olowen (Cilyan Olowen) Date: 2020-01-27 15:18
My bad, I did not check that asyncio.Event() was called before the application has a chance to properly set_event_loop with custom one.
Date User Action Args
2020-01-27 15:18:48Cilyan Olowensetmessages: + msg360772
2020-01-27 15:07:42Cilyan Olowensetnosy: + Cilyan Olowen
messages: + msg360770
2019-10-09 17:36:13yselivanovsetmessages: + msg354289
2019-10-09 17:15:18hniksicsettitle: Event loop implementation docs advertise set_event_loop -> Event loop implementation docs advertise set_event_loop which doesn't work with
2019-10-09 17:14:39hniksiccreate