Skip to content

Instantly share code, notes, and snippets.

@parlarjb
Created March 8, 2017 15:15
Show Gist options
  • Select an option

  • Save parlarjb/1a3311a5b89401b88d82765ab1052e85 to your computer and use it in GitHub Desktop.

Select an option

Save parlarjb/1a3311a5b89401b88d82765ab1052e85 to your computer and use it in GitHub Desktop.
class Logger(object):
def __enter__(self):
return self
def __exit__(self, exc_type, value, traceback):
print "Logging some stuff"
if exc_type is not None:
print "Sending exception up to New Relic"
........
In [16]: def foo():
....: with Logger():
....: yield 1
....: yield 2
....:
In [17]: f = foo()
In [18]: f.next()
Out[18]: 1
In [19]: del f
Logging some stuff
Sending exception up to New Relic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment