Created
March 8, 2017 15:15
-
-
Save parlarjb/1a3311a5b89401b88d82765ab1052e85 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
| 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