Finding count of currently open file descriptors.
andreas at kostyrka.priv.at
Thu Aug 1 10:37:17 CEST 2002
Am Die, 2002-07-30 um 16.31 schrieb Tim McNerney:
> > 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?
Well, an "easy" way would be:
for i in xrange(64*1024):
do something with fd
For do something, you can use fstat:
>>> def countfd():
... for i in xrange(64*1024):
... except os.error:
... return count
Only problem, scanning 64K descriptors take some seconds or so here.
Perhaps in your situation you could limit somehow the number that must
Even better, use isatty, on my Linux (Duron700 SonyFX201) system it's
fstat : 3.40730090141
I'l email you privatly the module with the countfd function.
More information about the Python-list