File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -1464,8 +1464,9 @@ execution passes to the task at the top of the queue. The queue is designed so
1464
1464
that even if the specified sleep is zero other due tasks will run before the
1465
1465
current one is resumed. This is "fair round-robin" scheduling. It is common
1466
1466
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:
1469
1470
1470
1471
``` python
1471
1472
async def bad_code ():
@@ -1477,7 +1478,7 @@ async def bad_code():
1477
1478
```
1478
1479
1479
1480
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:
1481
1482
1482
1483
``` python
1483
1484
async def good_code ():
You can’t perform that action at this time.
0 commit comments