Skip to content

Instantly share code, notes, and snippets.

@alonho
Created May 30, 2012 18:38
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 alonho/2838190 to your computer and use it in GitHub Desktop.
Save alonho/2838190 to your computer and use it in GitHub Desktop.
ExitStack.__exit__
def __exit__(self, *exc_details):
if not self._exit_callbacks:
return
for cb in reversed(self._exit_callbacks):
try:
supress_exc = cb(*exc_details)
except:
exc_details = sys.exc_info()
else:
if supress_exc:
exc_details = (None, None, None)
self._exit_callbacks = deque()
return supress_exc or exc_details == (None, None, None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment