[Python-Dev] Internal counter to debug leaking file descriptors (original) (raw)

Terry Reedy tjreedy at udel.edu
Fri Sep 3 19:14:38 CEST 2010


On 9/3/2010 6:09 AM, Giampaolo RodolĂ  wrote:

Of course it would be nice to get access to FD stack so that a full filename can also be retrieved in this case. On Linux, this can be easily achieved by using /proc. You can take a look at how this is done in the current development version of psutil: http://code.google.com/p/psutil/source/browse/trunk/psutil/pslinux.py?spec=svn633&r=630#266 Usage:

import psutil, os thisprocess = psutil.Process(os.getpid()) f = open('file.ext', 'w') thisprocess.getopenfiles() ['/home/giampaolo/svn/psutil/file.ext'] Same for sockets, a bunch of lines later: http://code.google.com/p/psutil/source/browse/trunk/psutil/pslinux.py?spec=svn633&r=630#284 import socket s = socket.createconnection(('google.com', 80)) thisprocess.getconnections() [connection(family=2, type=1, localaddress=('192.168.1.43', 38067), remoteaddress=('72.14.234.104', 80), status='ESTABLISHED')]

If you can use psutil itself, it has compiled Windows versions for 2.7 and 3.1 https://code.google.com/p/psutil/

-- Terry Jan Reedy



More information about the Python-Dev mailing list