Skip to content

Instantly share code, notes, and snippets.

@remleduff
Last active July 8, 2017 20:23
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 remleduff/fac512ac534cefc7ab4ae5421e4d4917 to your computer and use it in GitHub Desktop.
Save remleduff/fac512ac534cefc7ab4ae5421e4d4917 to your computer and use it in GitHub Desktop.
import trio
async def sleeper():
try:
await trio.sleep(30)
except KeyboardInterrupt:
print("KBInterrupt")
async def test():
with trio.open_cancel_scope() as cancel_scope:
cancel_scope.shield = True
# This cannot be interrupted by any means short of
# killing the process:
try:
await trio.sleep(10)
except KeyboardInterrupt:
print("KBInterrupt")
# This doesn't catch the KeyboardInterrupt
with trio.open_cancel_scope(shield=True):
async with trio.open_nursery() as nursery:
nursery.spawn(sleeper)
trio.run(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment