Created
August 30, 2018 01:48
-
-
Save lega911/7eaaa8e1adc14599e751929a0cbb9366 to your computer and use it in GitHub Desktop.
run callback on stop loop
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 | |
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