[issue38423] Event loop implementation docs advertise set_event_loop

Hrvoje Nikšić report at bugs.python.org
Wed Oct 9 13:14:39 EDT 2019


New submission from Hrvoje Nikšić <hniksic at gmail.com>:

The docs of SelectorEventLoop and ProactorEventLoop contain examples that call asyncio.set_event_loop:

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

But this won't have any effect on code that uses asyncio.run(), because asyncio.run() creates a fresh event loop. Since asyncio.run() 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 asyncio.run(), and that loop.run_until_complete() must be used; and

* link to asyncio.set_event_loop_policy(), which does work with asyncio.run(), but doesn't allow fine-tuning the details, such as which selector to use for the SelectorEventLoop.

----------
assignee: docs at python
components: Documentation, asyncio
messages: 354288
nosy: asvetlov, docs at python, hniksic, yselivanov
priority: normal
severity: normal
status: open
title: Event loop implementation docs advertise set_event_loop
versions: Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38423>
_______________________________________


More information about the Python-bugs-list mailing list