Created
July 30, 2019 11:08
-
-
Save ethe/4be0fc9d36dc038bb5b39c3247f5e6ab to your computer and use it in GitHub Desktop.
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 | |
async def sleep(): | |
print('start') | |
try: | |
await asyncio.sleep(100) | |
except: | |
print('canceld') | |
async def foo(): | |
task = asyncio.create_task(sleep()) | |
await asyncio.sleep(0) | |
task.cancel() | |
await asyncio.sleep(1) | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(foo()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment