From d22848c27fb8712f33f815e67b858f292f9bd8e1 Mon Sep 17 00:00:00 2001
From: Matthieu Imbert <matthieu.imbert@inria.fr>
Date: Fri, 27 May 2016 10:46:51 +0200
Subject: [PATCH] [2to3] factored and python3 compatible MAXFD computation in
 utils

---
 src/execo/conductor.py    | 9 ++-------
 src/execo/utils.py        | 5 +++++
 src/execo_engine/utils.py | 2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/execo/conductor.py b/src/execo/conductor.py
index 9857d7d9..3733d926 100644
--- a/src/execo/conductor.py
+++ b/src/execo/conductor.py
@@ -19,7 +19,7 @@
 from __future__ import print_function
 from .log import style, logger, logger_handler
 from .time_utils import format_unixts
-from .utils import compact_output
+from .utils import compact_output, MAXFD
 from .config import configuration
 import errno, fcntl, logging, os, select, \
   signal, sys, threading, time, traceback, \
@@ -44,8 +44,6 @@ try:
 except:
     _MAXREAD = 32767
 
-DEFAULT_MAXFD = 1024
-
 if sys.platform.startswith('darwin') or sys.platform.startswith('win'):
 
     # minimal abstraction of poll over select allowing the conductor
@@ -283,10 +281,7 @@ class _Conductor(object):
             os.umask(0)
             maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
             if (maxfd == resource.RLIM_INFINITY):
-                if ("SC_OPEN_MAX" in os.sysconf_names):
-                    maxfd = maxfd = os.sysconf("SC_OPEN_MAX")
-                else:
-                    maxfd = DEFAULT_MAXFD
+                maxfd = MAXFD
             for fd in range(0, maxfd):
                 try: os.close(fd)
                 except OSError: pass
diff --git a/src/execo/utils.py b/src/execo/utils.py
index 98ed9d0b..411b2f36 100644
--- a/src/execo/utils.py
+++ b/src/execo/utils.py
@@ -121,3 +121,8 @@ if sys.version_info >= (3,):
 else:
     def is_string(s):
         return isinstance(s, basestring)
+
+if ("SC_OPEN_MAX" in os.sysconf_names):
+    MAXFD = os.sysconf("SC_OPEN_MAX")
+else:
+    MAXFD = 1024
diff --git a/src/execo_engine/utils.py b/src/execo_engine/utils.py
index cbd0b400..d33337f8 100644
--- a/src/execo_engine/utils.py
+++ b/src/execo_engine/utils.py
@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with Execo.  If not, see <http://www.gnu.org/licenses/>
 
-from subprocess import MAXFD
+from execo.utils import MAXFD
 import os, unicodedata, re, sys, ctypes, signal
 
 def _redirect_fd(fileno, filename):
-- 
GitLab