Author klaas
Recipients hvbargen, klaas, loewis, pjdelport
Date 2007-10-16.04:05:37
SpamBayes Score 0.00208486
Marked as misclassified No
Message-id <1192507537.66.0.367321336905.issue1663329@psf.upfronthosting.co.za>
In-reply-to
Content
This problem has also afflicted us.

Attached is a patch which adds closerange(fd_low, fd_high) to the posix 
(and consequently os) module, and modifies subprocess to use it.  Patch 
is against trunk but should work for 2.5maint.

I don't really think that this is useful enough to add to the public 
api, but it results in a huge performance benefit for subprocess:

[python-trunk]$ ./python -m timeit -s 'import python_close' 
'python_close.go(100000)'
10 loops, best of 3: 358 msec per loop
[python-trunk]$ ./python -m timeit -s 'import os' 'os.closerange(4, 
100000)'
10 loops, best of 3: 20.7 msec per loop
[python-trunk]$ ./python -m timeit -s 'import python_close' 
'python_close.go(300000)'
10 loops, best of 3: 1.05 sec per loop
[python-trunk]$ ./python -m timeit -s 'import os' 'os.closerange(4, 
300000)'10 loops, best of 3: 63 msec per loop

[python-trunk]$ cat python_close.py
import os, sys
def go(N):
        for i in xrange(4, N):
                try:
                        os.close(i)
                except:
                        pass
Files
File name Uploaded
posix_closerange.patch klaas, 2007-10-16.04:05:37
History
Date User Action Args
2007-10-16 04:05:37klaassetspambayes_score: 0.00208486 -> 0.00208486
recipients: + klaas, loewis, pjdelport, hvbargen
2007-10-16 04:05:37klaassetspambayes_score: 0.00208486 -> 0.00208486
messageid: <1192507537.66.0.367321336905.issue1663329@psf.upfronthosting.co.za>
2007-10-16 04:05:37klaaslinkissue1663329 messages
2007-10-16 04:05:37klaascreate