summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMariatta <Mariatta@users.noreply.github.com>2018-10-24 22:37:12 (GMT)
committerVictor Stinner <vstinner@redhat.com>2018-10-24 22:37:12 (GMT)
commit9f43fbbd9dfc78125c9533ce1dfe33ff5d15aa45 (patch)
tree326f88801ff7ef63e2a8870495cf491e0cb5064b
parent057f4078b044325dae4af55c4c64b684edaca315 (diff)
downloadcpython-9f43fbbd9dfc78125c9533ce1dfe33ff5d15aa45.zip
cpython-9f43fbbd9dfc78125c9533ce1dfe33ff5d15aa45.tar.gz
cpython-9f43fbbd9dfc78125c9533ce1dfe33ff5d15aa45.tar.bz2
Use f-strings in asyncio-task code examples (GH-10035)
Replace str.format with f-strings in the code examples of asyncio-task documentation.
-rw-r--r--Doc/library/asyncio-task.rst12
1 files changed, 6 insertions, 6 deletions
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index ffeeb2d..5157f92 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -57,12 +57,12 @@ To actually run a coroutine asyncio provides three main mechanisms:
print(what)
async def main():
- print('started at', time.strftime('%X'))
+ print(f"started at {time.strftime('%X')}")
await say_after(1, 'hello')
await say_after(2, 'world')
- print('finished at', time.strftime('%X'))
+ print(f"finished at {time.strftime('%X')}")
asyncio.run(main())
@@ -86,14 +86,14 @@ To actually run a coroutine asyncio provides three main mechanisms:
task2 = asyncio.create_task(
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
# around 2 seconds.)
await task1
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
1 second faster than before::
@@ -603,9 +603,9 @@ Scheduling From Other Threads
print('The coroutine took too long, cancelling the task...')
future.cancel()
except Exception as exc:
- print('The coroutine raised an exception: {!r}'.format(exc))
+ print(f'The coroutine raised an exception: {exc!r}')
else:
- print('The coroutine returned: {!r}'.format(result))
+ print(f'The coroutine returned: {result!r}')
See the :ref:`concurrency and multithreading <asyncio-multithreading>`
section of the documentation.