[Python-Dev] closing files and sockets in a timely manner in the stdlib

Brett Cannon brett at python.org
Sat Oct 30 02:35:36 CEST 2010


For those of you who have not noticed, Antoine committed a patch that
raises a ResourceWarning under a pydebug build if a file or socket is
closed through garbage collection instead of being explicitly closed.

I have started to go through the test suite to fix as many of these
cases as possible, but it's time for me to stop. For those of you
interested in helping out, at the end of this email is a list of tests
which have some ResourceWarning raised. Some of them are probably
listed here because of some other module causing the problem.
Everything from test_mailbox and *up* I already tried to silence but
it the solution was non-obvious to me (or was very network-specific
which I don't have much experience with). from test_os *down* I have
not touched (although Antoine has gotten to some).

Just a little tip: if testMethod() comes up as the warning in unittest
it isn't unittest. =) Because the warning gets triggered at odd times
thanks to gc it doesn't always output a helpful line. Best thing is to
search for obvious things like "open(" or "socket(" to find things
that need a context manager if the line where the warning triggered
seems odd (both in the test and in the module being tested).



[ 92/349] test_distutils

[105/349] test_file

[108/349] test_fileio

[116/349] test_ftplib

[143/349] test_httplib

[144/349] test_httpservers

[154/349] test_io

[169/349] test_logging

[173/349] test_mailbox



[197/349] test_os

[214/349] test_pkgimport

[219/349] test_popen

[247/349] test_sax

[255/349] test_shutil

[260/349] test_smtplib

[263/349] test_socket

[267/349] test_ssl

[278/349] test_subprocess

[279/349] test_sunau

[289/349] test_tarfile

[291/349] test_telnetlib

[297/349] test_threading

[303/349] test_tokenize

[314/349] test_unicodedata

[320/349] test_urllib2_localnet

[328/349] test_uu

[343/349] test_xmlrpc

[345/349] test_zipfile


More information about the Python-Dev mailing list