Skip to content

Instantly share code, notes, and snippets.

@lega911
Created August 30, 2018 01:48
Show Gist options
  • Save lega911/7eaaa8e1adc14599e751929a0cbb9366 to your computer and use it in GitHub Desktop.
Save lega911/7eaaa8e1adc14599e751929a0cbb9366 to your computer and use it in GitHub Desktop.
run callback on stop loop
import asyncio
async def main():
print('start')
async def on_stop():
try:
await asyncio.sleep(10**10)
except asyncio.CancelledError:
pass
print('stopping start')
await asyncio.sleep(1)
print('stopping end')
asyncio.ensure_future(on_stop())
await asyncio.sleep(1)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment