Finding count of currently open file descriptors.

Martin v. Löwis loewis at informatik.hu-berlin.de
Tue Jul 30 10:22:19 EDT 2002


Tim McNerney <tmcnerney at truis.com> writes:

> How do I go about finding out the number of file descriptors currently
> open in a program? 

Depends on your operating system. On Linux, /proc/self/fd contains
this information.

In a Python debug build, you can find out all file objects, but there
may be file descriptors not controlled by Python file objects (e.g. if
opened by os.open).

> I'm trying to track down a file descriptor leak which may or may not
> be in library calls. Will I run into problems getting an accurate
> count due to the possible delay between doing a close and GC?

If you do a close, the file is closed immediately (i.e. when the close
returns). Cyclic GC is usually irrelevant, since file objects cannot
participate in a cycle - they can, however, be referred to from a
cycle.

Regards,
Martin



More information about the Python-list mailing list