--- Lib/subprocess.py +++ Lib/subprocess.py @@ -370,17 +370,20 @@ class pywintypes: error = IOError else: - import select - _has_poll = hasattr(select, 'poll') import errno - import fcntl - import pickle + try: + import select + except ImportError: + select = None + _has_poll = hasattr(select, 'poll') # When select or poll has indicated that the file is writable, # we can write up to _PIPE_BUF bytes without risk of blocking. # POSIX defines PIPE_BUF as >= 512. _PIPE_BUF = getattr(select, 'PIPE_BUF', 512) + del select + __all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "getstatusoutput", "getoutput", "check_output", "CalledProcessError"] @@ -1007,12 +1010,18 @@ def _set_cloexec_flag(self, fd): try: - cloexec_flag = fcntl.FD_CLOEXEC - except AttributeError: - cloexec_flag = 1 + import fcntl - old = fcntl.fcntl(fd, fcntl.F_GETFD) - fcntl.fcntl(fd, fcntl.F_SETFD, old | cloexec_flag) + try: + cloexec_flag = fcntl.FD_CLOEXEC + except AttributeError: + cloexec_flag = 1 + + old = fcntl.fcntl(fd, fcntl.F_GETFD) + fcntl.fcntl(fd, fcntl.F_SETFD, old | cloexec_flag) + except ImportError: + # fcntl module cannot be used when building Python. + pass def _close_fds(self, but): @@ -1105,6 +1114,7 @@ os.execvpe(executable, args, env) except: + import pickle exc_type, exc_value, tb = sys.exc_info() # Save the traceback and attach it to the exception # object @@ -1140,6 +1150,7 @@ os.close(errpipe_read) if data: + import pickle os.waitpid(self.pid, 0) child_exception = pickle.loads(data) for fd in (p2cwrite, c2pread, errread): @@ -1215,6 +1226,7 @@ def _communicate_with_poll(self, input): + import select stdout = None # Return stderr = None # Return fd2file = {} @@ -1272,6 +1284,7 @@ def _communicate_with_select(self, input): + import select read_set = [] write_set = [] stdout = None # Return