In which rogue call_soons starve cooperating callbacks.
This file contains 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 | |
loop = asyncio.get_event_loop() | |
async def go(sleep): | |
await asyncio.sleep(sleep) | |
print('I slept', sleep, 'seconds') | |
def clog(sleep): | |
time.sleep(sleep) | |
print('I clogged', sleep, 'seconds') | |
loop.call_at(loop.time() + 0.3, lambda: print('here I am')) | |
loop.create_task(go(1)) | |
loop.create_task(go(2)) | |
loop.create_task(go(3)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.call_soon(lambda: clog(1)) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know what you're trying to prove here. Of course the event loop is unavailable when a coroutine calls
time.sleep()
.