Last active
July 8, 2017 20:23
-
-
Save remleduff/fac512ac534cefc7ab4ae5421e4d4917 to your computer and use it in GitHub Desktop.
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 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