classification
Title: A "Coroutines and Tasks" code example needs "asyncio.run(main())"
Type: enhancement Stage:
Components: Documentation Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: AtsushiSakai, andrei.avk, docs@python
Priority: normal Keywords:

Created on 2021-06-13 05:17 by AtsushiSakai, last changed 2021-06-15 14:39 by andrei.avk.

Messages (2)
msg395728 - (view) Author: Atsushi Sakai (AtsushiSakai) Date: 2021-06-13 05:17
This is very small documentation improvement proposal.

In the "Coroutines and Tasks" doc, the code example after "Let’s modify the above example and run two say_after coroutines concurrently:" is missing "asyncio.run(main())" at the end of the code example:

async def main():
    task1 = asyncio.create_task(
        say_after(1, 'hello'))

    task2 = asyncio.create_task(
        say_after(2, 'world'))

    print(f"started at {time.strftime('%X')}")

    # Wait until both tasks are completed (should take
    # around 2 seconds.)
    await task1
    await task2

    print(f"finished at {time.strftime('%X')}")
msg395882 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-06-15 14:39
I think it's clear that the modification of previous example is limited to `main()` because `say_after()` is also omitted. This is very common in Python code examples, - it seems to me this change is not needed.
History
Date User Action Args
2021-06-15 14:39:52andrei.avksetnosy: + andrei.avk
messages: + msg395882
2021-06-13 05:17:43AtsushiSakaicreate