[Python-Dev] [Python-checkins] r85987 - python/branches/py3k/Lib/test/test_os.py

Antoine Pitrou solipsis at pitrou.net
Thu Nov 4 15:23:58 CET 2010


On Thu, 04 Nov 2010 23:09:39 +0900
Hirokazu Yamamoto <ocean-city at m2.ccsnet.ne.jp> wrote:
> On 2010/11/02 1:30, Nick Coghlan wrote:
> > On Tue, Nov 2, 2010 at 2:10 AM, Hirokazu Yamamoto
> > <ocean-city at m2.ccsnet.ne.jp>  wrote:
> >> Does this really cause resource warning? I think os.popen instance
> >> won't be into traceback because it's not declared as variable. So I
> >> suppose it will be deleted by reference count == 0 even when exception
> >> occurs.
> >
> > Any time __del__ has to close the resource triggers ResourceWarning,
> > regardless of whether that is due to the cyclic garbage collector or
> > the refcount naturally falling to zero. In the past dealing with this
> > was clumsy, so it made sense to rely on CPython's refcounting to do
> > the work. However, we have better tools for deterministic resource
> > management now (in the form of context managers), so these updates
> > help make the standard library and its test suite more suitable for
> > use with non-refcounting Python implementations (such as PyPy, Jython
> > and IronPython).
> >
> > Cheers,
> > Nick.
> >
> 
> Thank you for reply. Probably this is difficult problem. I often
> use with statement, but it's also true sometimes I feel this warning is
> a bit noisy. Is there a way to turn this off?

You can use all the usual means of controlling emission of warnings, so
for example "python -Wi" would work to silence them all.
Also, ResourceWarning is silenced by default in "release" builds.

Regards

Antoine.




More information about the Python-Dev mailing list