(original) (raw)
On Oct 30, 2010, at 2:39 PM, Jack Diederich wrote:
On Fri, Oct 29, 2010 at 8:35 PM, Brett Cannon <brett@python.org> wrote:For those of you who have not noticed, Antoine committed a patch thatraises a ResourceWarning under a pydebug build if a file or socket isclosed 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".
A more portable (albeit not standard) path for "what file descriptors do I have open" is /dev/fd/. This is supported via a symlink to /proc/self on all the Linuxes I've tested on. There's no portable standard equivalent for not-yourself processes that I'm aware of, though.
See more discussion here: <http://twistedmatrix.com/trac/ticket/4522>.