Skip to content

Instantly share code, notes, and snippets.

@ethe
Created July 30, 2019 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethe/4be0fc9d36dc038bb5b39c3247f5e6ab to your computer and use it in GitHub Desktop.
Save ethe/4be0fc9d36dc038bb5b39c3247f5e6ab to your computer and use it in GitHub Desktop.
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