mirror of
https://github.com/python/cpython.git
synced 2025-11-07 21:29:26 +00:00
Use f-strings in asyncio-task code examples (GH-10035)
Replace str.format with f-strings in the code examples of asyncio-task documentation.
This commit is contained in:
parent
057f4078b0
commit
9f43fbbd9d
1 changed files with 6 additions and 6 deletions
|
|
@ -57,12 +57,12 @@ To actually run a coroutine asyncio provides three main mechanisms:
|
||||||
print(what)
|
print(what)
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
print('started at', time.strftime('%X'))
|
print(f"started at {time.strftime('%X')}")
|
||||||
|
|
||||||
await say_after(1, 'hello')
|
await say_after(1, 'hello')
|
||||||
await say_after(2, 'world')
|
await say_after(2, 'world')
|
||||||
|
|
||||||
print('finished at', time.strftime('%X'))
|
print(f"finished at {time.strftime('%X')}")
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|
@ -86,14 +86,14 @@ To actually run a coroutine asyncio provides three main mechanisms:
|
||||||
task2 = asyncio.create_task(
|
task2 = asyncio.create_task(
|
||||||
say_after(2, 'world'))
|
say_after(2, 'world'))
|
||||||
|
|
||||||
print('started at', time.strftime('%X'))
|
print(f"started at {time.strftime('%X')}")
|
||||||
|
|
||||||
# Wait until both tasks are completed (should take
|
# Wait until both tasks are completed (should take
|
||||||
# around 2 seconds.)
|
# around 2 seconds.)
|
||||||
await task1
|
await task1
|
||||||
await task2
|
await task2
|
||||||
|
|
||||||
print('finished at', time.strftime('%X'))
|
print(f"finished at {time.strftime('%X')}")
|
||||||
|
|
||||||
Note that expected output now shows that the snippet runs
|
Note that expected output now shows that the snippet runs
|
||||||
1 second faster than before::
|
1 second faster than before::
|
||||||
|
|
@ -603,9 +603,9 @@ Scheduling From Other Threads
|
||||||
print('The coroutine took too long, cancelling the task...')
|
print('The coroutine took too long, cancelling the task...')
|
||||||
future.cancel()
|
future.cancel()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print('The coroutine raised an exception: {!r}'.format(exc))
|
print(f'The coroutine raised an exception: {exc!r}')
|
||||||
else:
|
else:
|
||||||
print('The coroutine returned: {!r}'.format(result))
|
print(f'The coroutine returned: {result!r}')
|
||||||
|
|
||||||
See the :ref:`concurrency and multithreading <asyncio-multithreading>`
|
See the :ref:`concurrency and multithreading <asyncio-multithreading>`
|
||||||
section of the documentation.
|
section of the documentation.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue