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

Jack Diederich jackdied at gmail.com
Sat Oct 30 22:04:39 CEST 2010

On Sat, Oct 30, 2010 at 3:06 PM, Glyph Lefkowitz
<glyph at twistedmatrix.com> wrote:
> On Oct 30, 2010, at 2:39 PM, Jack Diederich wrote:
> On Fri, Oct 29, 2010 at 8:35 PM, Brett Cannon <brett at python.org> wrote:
> 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.
> Just yesterday I discovered /proc/<your PID here>/fd/ which is a list
> of open file descriptors for your PID on *nix and includes all open
> files, pipes, and sockets.  Very handy, I filed some tickets about
> company internal libs that were opening file handles as a side effect
> of import (logging mostly).  I tried to provoke standard python
> imports (non-test) to leave some open handles and came up empty.
> That path (and anything below /proc, really) is a list of open file
> descriptors specifically on Linux, not "*nix".  Also on linux, you can avoid
> "<your pid here>" by just doing "/proc/self".

I was happy to find out that the /proc system came from Plan9 because
I always thought Plan9 was dead water.  But in this particular case
Plan9 outdid System7 in the the realm of "everything is a file" by
making everything a file.

More information about the Python-Dev mailing list