Message129043
when use popen*() and close_fds is True, python will close unused fds. but the MAXFD is not the real max. especially in freebsd, subprocess.MAXFD=655000. so python will try to close to many fd, it's too slow, in my test on freebsd, using about 3 seconds.
poor english.
patch for 2.7 trunck:
jiangxiaobing@s7v7nislands ~/source/svn/python27 $ svn diff
Index: Lib/subprocess.py
===================================================================
--- Lib/subprocess.py (revision 88499)
+++ Lib/subprocess.py (working copy)
@@ -1065,11 +1065,16 @@
def _close_fds(self, but):
+ maxfd = MAX_FD
+ try:
+ maxfd = os.dup(0) + 1
+ except:
+ pass
if hasattr(os, 'closerange'):
os.closerange(3, but)
- os.closerange(but + 1, MAXFD)
+ os.closerange(but + 1, maxfd)
else:
- for i in xrange(3, MAXFD):
+ for i in xrange(3, maxfd):
if i == but:
continue
try:
Index: Lib/popen2.py
===================================================================
--- Lib/popen2.py (revision 88499)
+++ Lib/popen2.py (working copy)
@@ -82,8 +82,13 @@
def _run_child(self, cmd):
if isinstance(cmd, basestring):
cmd = ['/bin/sh', '-c', cmd]
- os.closerange(3, MAXFD)
+ maxfd = MAXFD
try:
+ maxfd = os.dup(0) + 1
+ except:
+ pass
+ os.closerange(3, maxfd)
+ try:
os.execvp(cmd[0], cmd)
finally:
os._exit(1)
patch for 3.3 truck:
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index c02fb52..98a25b3 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1112,8 +1112,14 @@ class Popen(object):
if fd >= start_fd:
os.closerange(start_fd, fd)
start_fd = fd + 1
- if start_fd <= MAXFD:
- os.closerange(start_fd, MAXFD)
+ maxfd = MAXFD
+ try:
+ maxfd = os.dup(0) + 1
+ except:
+ pass
+
+ if start_fd <= maxfd:
+ os.closerange(start_fd, maxfd)
def _execute_child(self, args, executable, preexec_fn, close_fds, |
|
Date |
User |
Action |
Args |
2011-02-22 09:38:11 | s7v7nislands | set | recipients:
+ s7v7nislands |
2011-02-22 09:38:11 | s7v7nislands | set | messageid: <1298367491.02.0.82009440358.issue11284@psf.upfronthosting.co.za> |
2011-02-22 09:38:09 | s7v7nislands | link | issue11284 messages |
2011-02-22 09:38:09 | s7v7nislands | create | |
|