Skip to content

Instantly share code, notes, and snippets.

@jbdrvl
Created May 1, 2018 15:35
Show Gist options
  • Select an option

  • Save jbdrvl/e934e4d846667e4602566a0ceab5c7ee to your computer and use it in GitHub Desktop.

Select an option

Save jbdrvl/e934e4d846667e4602566a0ceab5c7ee to your computer and use it in GitHub Desktop.
Test of the {<try>, <finally>} keywords.
#!/usr/bin/env python3
'''
Will loop infinitely until stopped by the user (ctrl+C).
When interrupted, the program will print "Leaving main!" before raising the <KeyboardInterrupt> exception.
Not very useful but I thought it was pretty cool.
'''
def main():
try:
while True:
pass
finally:
print("Leaving main!")
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment