Created
April 10, 2014 11:02
-
-
Save kubek2k/10368672 to your computer and use it in GitHub Desktop.
Context manager example
This file contains 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 X: | |
def __enter__(self): | |
print "entering" | |
def __exit__(self, exception_type, exception_val, trace): | |
print "exiting" | |
def restart(): | |
return X() | |
def loadbalancer(): | |
return X() | |
with loadbalancer(): | |
with restart(): | |
print "abcd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment