homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nikratio
Recipients nikratio
Date 2011年12月12日.01:49:49
SpamBayes Score 4.394125e-08
Marked as misclassified No
Message-id <1323654590.86.0.53041507768.issue13585@psf.upfronthosting.co.za>
In-reply-to
Content
I'd like to propose addding the CleanupManager class described in http://article.gmane.org/gmane.comp.python.ideas/12447 to the contextlib module. The idea is to add a general-purpose context manager to manage (python or non-python) resources that don't come with their own context manager.
Example code:
with CleanupManager() als mngr:
 tmpdir = tempfile.mkdtemp()
 mngr.register(shutil.rmtree(tmpdir))
 # do stuff with tmpdir
# shutil.rmtree() get's called automatically when the block is over
Note that mkdtemp() could of course also be changed to become its own context manager. The idea is to provide a general facility for this kind of problem, so it doesn't have to be reinvented whenever a module provides a ressource without its own context manager. Other possible uses are of course ressources that are completely external to Python,
e.g. anything allocated with a subprocess (think of subprocess.check_call('mount'))/
I'll be happy to make a proper patch with documentation and testcases from Jan's code. As a matter of fact, I'll probably start working out it right now, so please let me know quickly if this doesn't have a chance of getting accepted.
History
Date User Action Args
2011年12月12日 01:49:50nikratiosetrecipients: + nikratio
2011年12月12日 01:49:50nikratiosetmessageid: <1323654590.86.0.53041507768.issue13585@psf.upfronthosting.co.za>
2011年12月12日 01:49:50nikratiolinkissue13585 messages
2011年12月12日 01:49:49nikratiocreate

AltStyle によって変換されたページ (->オリジナル) /