Skip to content

Instantly share code, notes, and snippets.

@goyalrohit
Created February 1, 2018 10:19
Show Gist options
  • Save goyalrohit/2826684ace0e6466847e223cd8444bd6 to your computer and use it in GitHub Desktop.
Save goyalrohit/2826684ace0e6466847e223cd8444bd6 to your computer and use it in GitHub Desktop.
import contextlib
import sys
@contextlib.contextmanager
def logging_context_manager():
print('logging_context_manager: enter')
try:
yield 'You are in a with-block!'
print('logging_context_manager: normal exit')
except Exception:
print('logging_context_manager: exceptional exit',sys.exc_info())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment