Éric Araujo mer...@netwok.org added the comment:
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.
I read the thread back on python-ideas and didn’t like the idea, without
knowing exactly why—maybe
Nikolaus Rath nikol...@rath.org added the comment:
On 12/21/2011 11:46 AM, Éric Araujo wrote:
Éric Araujo mer...@netwok.org added the comment:
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.
Éric Araujo mer...@netwok.org added the comment:
In the passage I quoted, I don’t understand what is meant by “non-Python
resources”.
Think about e.g. mounting a file system.
Ah, ok. In that case there would still be a Python-level object (just like a
Python file object will also release
Nikolaus Rath nikol...@rath.org added the comment:
On 12/21/2011 12:03 PM, Éric Araujo wrote:
Éric Araujo mer...@netwok.org added the comment:
In the passage I quoted, I don’t understand what is meant by “non-Python
resources”.
Think about e.g. mounting a file system.
Ah, ok. In
Nick Coghlan ncogh...@gmail.com added the comment:
My earlier descriptions here aren't really adequate - as soon as I started
putting contextlib2 together, this CleanupManager idea quickly morphed into
ContextStack [1], which is a far more powerful tool for manipulating context
managers in a
Raymond Hettinger raymond.hettin...@gmail.com added the comment:
Thanks Nick. You're awesome.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13585
___
Nick Coghlan ncogh...@gmail.com added the comment:
And the backport: http://contextlib2.readthedocs.org/
I haven't tested on anything other than 2.7 as yet - I have an account request
in train with the Shining Panda folks, so I'll set up multi-version CI for this
project (along with a couple
Sven Marnach s...@marnach.net added the comment:
I think that the fact that Nick got the code to close multiple files wrong
underlines that it is difficult to get right currently. Nick's code
try:
files = [open(fname) for fname in names]
# ...
finally:
for f in
Nikolaus Rath nikol...@rath.org added the comment:
On 12/11/2011 10:17 PM, Raymond Hettinger wrote:
Raymond Hettinger raymond.hettin...@gmail.com added the comment:
'''
Example code:
with CleanupManager() als mngr:
tmpdir = tempfile.mkdtemp()
Changes by Nikolaus Rath nikol...@rath.org:
Added file: http://bugs.python.org/file23933/CleanupManager_patch_v2.diff
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13585
___
Changes by Giampaolo Rodola' g.rod...@gmail.com:
--
nosy: +giampaolo.rodola
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13585
___
___
Sven Marnach s...@marnach.net added the comment:
There is actually a second thread on python-ideas on a very similar topic, see
http://mail.python.org/pipermail/python-ideas/2011-December/013021.html
The two main advantages of the proposed CleanupManager over try/finally blocks
are
1.
Nikolaus Rath nikol...@rath.org added the comment:
On 12/12/2011 03:31 PM, Sven Marnach wrote:
Adding this as a cookbook recipe first seems like a good idea.
This is the second time that this is mentioned, so I would be very
grateful if someone could elucidate what adding as a cookbook recipe
Eric Snow ericsnowcurren...@gmail.com added the comment:
Check out: http://code.activestate.com/recipes/
--
nosy: +eric.snow
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13585
___
Julian Berman julian+python@grayvines.com added the comment:
For reference, the implementation that I posted in the other thread is:
@contextlib.contextmanager
def maybe(got, contextfactory, *args, checkif=bool, **kwargs):
if checkif(got):
yield got
else:
Nick Coghlan ncogh...@gmail.com added the comment:
Given the existence of tempfile.TemporaryDirectory in recent Python versions, I
suggest finding a new cleanup function example that doesn't duplicate native
stdlib functionality :)
I do see value in the feature itself though - I believe the
Raymond Hettinger raymond.hettin...@gmail.com added the comment:
I think you guys need to post your code somewhere (perhaps on PyPi or the ASPN
Cookbook). It needs to mature beyond the stage of I just whipped-up this code
and think it would be great if everybody used it.
I've seen nothing
Changes by Raymond Hettinger raymond.hettin...@gmail.com:
--
assignee: - rhettinger
resolution: - later
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13585
___
Nick Coghlan ncogh...@gmail.com added the comment:
TestCase.setUp() and TestCase.tearDown() were amongst the precursors
to__enter__() and __exit__(). addCleanUp() fills exactly the same role here -
and I've seen *plenty* of positive feedback directed towards Michael for that
addition to the
Nick Coghlan ncogh...@gmail.com added the comment:
Given the history of API design errors in contextlib (cf. contextlib.nested in
general, making contextlib._GeneratorContextManager a subclass of
contextlib.ContextDecorator), I've realised Raymond is right in wanting to see
this idea more
Nick Coghlan ncogh...@gmail.com added the comment:
In the meantime, I put my version up as a cookbook recipe:
http://code.activestate.com/recipes/577981-cleanupmanager-for-with-statements/
--
___
Python tracker rep...@bugs.python.org
New submission from Nikolaus Rath nikol...@rath.org:
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)
Nikolaus Rath nikol...@rath.org added the comment:
Here's the first part of the patch with the implementation. I'll add tests and
documentation as soon as someone confirms that the idea API is okay.
--
keywords: +patch
Added file:
Raymond Hettinger raymond.hettin...@gmail.com added the comment:
I would like to see this posted as a recipe before being put in the standard
library. It needs a chance to mature and to demonstrate that people will want
to use it.
FWIW, the example is problematic in a couple of ways. The
Nikolaus Rath nikol...@rath.org added the comment:
Not sure what you mean with posted as a recipe -- are you thinking of a
specific website/mailing list?
Example: which one do you mean? The one in the issue or the one in the patch?
With statement: what advantages do you have in mind?
Raymond Hettinger raymond.hettin...@gmail.com added the comment:
'''
Example code:
with CleanupManager() als mngr:
tmpdir = tempfile.mkdtemp()
mngr.register(shutil.rmtree(tmpdir)) -- this makes the call right away
# do stuff with tmpdir
'''
The part of my note that should be clear
26 matches
Mail list logo