Skip to content

Instantly share code, notes, and snippets.

@ambv
Created June 2, 2016 19:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
In which rogue call_soons starve cooperating callbacks.
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()
@gvanrossum
Copy link

I don't know what you're trying to prove here. Of course the event loop is unavailable when a coroutine calls time.sleep().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment