Created
July 31, 2026 14:36
-
-
Save jordanorelli/96be563fad4cd08af2ed17a239c149a3 to your computer and use it in GitHub Desktop.
asyncio scheduler contention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import time | |
| async def badguy(): | |
| # await asyncio.sleep(0.001) # 1ms | |
| time.sleep(0.499) # 499ms | |
| async def goodguy(): | |
| start = time.perf_counter() | |
| await asyncio.sleep(0.01) # 10ms | |
| elapsed = time.perf_counter() - start | |
| print(f"goodguy took {elapsed}") | |
| async def main(): | |
| await asyncio.gather(badguy(), goodguy()) | |
| await asyncio.gather(goodguy(), badguy()) | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment