Finding count of currently open file descriptors.

Tim McNerney mumbly at oneofus.org
Tue Jul 30 10:31:24 EDT 2002


Martin v. Löwis wrote:
> 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).

This is more what I'm looking for -- some generic method which is within 
Python itself. How would I go about doing this within the debug build?

> 
>>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.

Thanks.

--Tim




More information about the Python-list mailing list