From a451bc454bf76f646e0f13c7f48a4fdd7df626e3 Mon Sep 17 00:00:00 2001 From: "Kulothungan U.G" Date: Wed, 19 Jul 2023 21:14:51 +0530 Subject: [PATCH 1/2] Update tutorial.rst --- docs/source/tutorial.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/tutorial.rst b/docs/source/tutorial.rst index 0faffd119b..0584446fb7 100644 --- a/docs/source/tutorial.rst +++ b/docs/source/tutorial.rst @@ -436,15 +436,15 @@ Now that we understand ``async with``, let's look at ``parent`` again: :end-at: all done! There are only 4 lines of code that really do anything here. On line -17, we use :func:`trio.open_nursery` to get a "nursery" object, and +20, we use :func:`trio.open_nursery` to get a "nursery" object, and then inside the ``async with`` block we call ``nursery.start_soon`` twice, -on lines 19 and 22. There are actually two ways to call an async +on lines 22 and 25. There are actually two ways to call an async function: the first one is the one we already saw, using ``await async_fn()``; the new one is ``nursery.start_soon(async_fn)``: it asks Trio to start running this async function, *but then returns immediately without waiting for the function to finish*. So after our two calls to ``nursery.start_soon``, ``child1`` and ``child2`` are now running in the -background. And then at line 25, the commented line, we hit the end of +background. And then at line 28, the commented line, we hit the end of the ``async with`` block, and the nursery's ``__aexit__`` function runs. What this does is force ``parent`` to stop here and wait for all the children in the nursery to exit. This is why you have to use From 00816bf53330c5b4cf65d1229f5248d6ae86ba88 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Thu, 20 Jul 2023 13:01:38 +0200 Subject: [PATCH 2/2] update emphasized lines --- docs/source/reference-core.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/reference-core.rst b/docs/source/reference-core.rst index 141e128026..b434a13273 100644 --- a/docs/source/reference-core.rst +++ b/docs/source/reference-core.rst @@ -1167,7 +1167,7 @@ the previous version, and then exits cleanly. The only change is the addition of ``async with`` blocks inside the producer and consumer: .. literalinclude:: reference-core/channels-shutdown.py - :emphasize-lines: 10,15 + :emphasize-lines: 11,17 The really important thing here is the producer's ``async with`` . When the producer exits, this closes the ``send_channel``, and that @@ -1246,7 +1246,7 @@ Fortunately, there's a better way! Here's a fixed version of our program above: .. literalinclude:: reference-core/channels-mpmc-fixed.py - :emphasize-lines: 7, 9, 10, 12, 13 + :emphasize-lines: 8, 10, 11, 13, 14 This example demonstrates using the `MemorySendChannel.clone` and `MemoryReceiveChannel.clone` methods. What these do is create copies