Skip to content

Instantly share code, notes, and snippets.

@kubek2k
Created April 10, 2014 11:02
Show Gist options
  • Save kubek2k/10368672 to your computer and use it in GitHub Desktop.
Save kubek2k/10368672 to your computer and use it in GitHub Desktop.
Context manager example
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