Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created December 31, 2013 11:26
Show Gist options
  • Save Kwpolska/8195509 to your computer and use it in GitHub Desktop.
Save Kwpolska/8195509 to your computer and use it in GitHub Desktop.
class Cleanable(object):
def __init__(self):
self.resources = []
def add_resource(self, name, obj):
setattr(self, name, obj)
self.resources.append(obj)
def close(self):
for res in self.resources:
res.close()
class ManyResources(Cleanable):
def __init__(self):
super(ManyResources, self).__init__()
try:
self.add_resource('resource1', Resource1)
self.add_resource('resource2', Resource2)
self.add_resource('resource3', Resource3)
self.add_resource('resource4', Resource4)
except (Resource1Error, Resource2Error, Resource3Error, Resource4Error) as e:
self.close()
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment