Skip to content

Commit a76909a

Browse files
committed
Tutorial: expand beginner section 7.
1 parent dab6805 commit a76909a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

TUTORIAL.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,9 @@ execution passes to the task at the top of the queue. The queue is designed so
14641464
that even if the specified sleep is zero other due tasks will run before the
14651465
current one is resumed. This is "fair round-robin" scheduling. It is common
14661466
practice to issue `await asyncio.sleep(0)` in loops to ensure a task doesn't
1467-
hog execution. The following shows a busy-wait loop which monopolises the CPU
1468-
preventing other coros from running:
1467+
hog execution. The following shows a busy-wait loop which waits for another
1468+
task to set the global `flag`. Alas it monopolises the CPU preventing other
1469+
coros from running:
14691470

14701471
```python
14711472
async def bad_code():
@@ -1477,7 +1478,7 @@ async def bad_code():
14771478
```
14781479

14791480
The problem here is that while the `flag` is `False` the loop never yields to
1480-
the scheduler so no other task will get to run. The fix is:
1481+
the scheduler so no other task will get to run. The correct approach is:
14811482

14821483
```python
14831484
async def good_code():

0 commit comments

Comments
 (0)