[issue21067] Support Multiple finally clauses.

Josh Rosenberg report at bugs.python.org
Wed Mar 26 04:58:27 CET 2014


Josh Rosenberg added the comment:

And for this particular case, even if the resource allocators don't support the context manager protocol, contextlib.closing can do the job:

    from contextlib import closing

    with closing(allocateresource1()) as resource1, closing(allocateresource2()) as resource2:
	dostuffthatmightthrowexception()

If it's not a simple as calling close, you can write your own simple manager wrapper that calls some other cleanup function use @contextlib.contextmanager.

----------
nosy: +josh.rosenberg

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21067>
_______________________________________


More information about the Python-bugs-list mailing list