Created
August 19, 2019 07:43
-
-
Save meysampg/11316dc12844a3fdf0862955067e4110 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
from contextlib import ExitStack | |
from functools import partial | |
# In some situation it's needed to care about program termination, explicitly or implicitly (by kill or raising an | |
# exception in the flow), situation likes send a notification on termination. For this purpose we can use contextlib | |
# of Python. Define our callbacks and put our main in an ExitStack. For more information see | |
# https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack | |
def printStars(): | |
print("*********************************") | |
def someBuggyFunction(): | |
for i in range(5): | |
print(i) | |
raise Exception("Hello World") | |
with ExitStack() as stack: | |
stack.callback(partial(printStars)) | |
someBuggyFunction() | |
print("you never see this") |
Author
meysampg
commented
Aug 19, 2019
I really miss the defer
of GO in python 😢.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment