Skip to content

Instantly share code, notes, and snippets.

@bashkirtsevich
Created September 17, 2018 19:29
Show Gist options
  • Select an option

  • Save bashkirtsevich/ace8add55ac7405b44aa77bfd6db8ec4 to your computer and use it in GitHub Desktop.

Select an option

Save bashkirtsevich/ace8add55ac7405b44aa77bfd6db8ec4 to your computer and use it in GitHub Desktop.
Asyncio tasks
import asyncio
async def slow_operation():
await asyncio.sleep(1)
return 'Future is done!'
def got_result(future):
print(future.result())
# We have result, so let's stop
loop.stop()
loop = asyncio.get_event_loop()
task = loop.create_task(slow_operation())
task.add_done_callback(got_result)
# We run forever
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment