diff -r d08d1569aa04 Lib/subprocess.py --- a/Lib/subprocess.py Wed Jul 23 14:40:27 2014 -0500 +++ b/Lib/subprocess.py Thu Jul 24 10:29:00 2014 -0500 @@ -356,8 +356,6 @@ """ import sys -mswindows = (sys.platform == "win32") - import io import os import time @@ -369,6 +367,16 @@ from time import monotonic as _time except ImportError: from time import time as _time +try: + import threading +except ImportError: + import dummy_threading as threading +try: + import msvcrt + import _winapi + mswindows = True +except ImportError: + mswindows = False # Exception classes used by this module. class SubprocessError(Exception): pass @@ -401,40 +409,6 @@ return ("Command '%s' timed out after %s seconds" % (self.cmd, self.timeout)) - -if mswindows: - import threading - import msvcrt - import _winapi - class STARTUPINFO: - dwFlags = 0 - hStdInput = None - hStdOutput = None - hStdError = None - wShowWindow = 0 -else: - import _posixsubprocess - import select - import selectors - try: - import threading - except ImportError: - import dummy_threading as threading - - # 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) - - # poll/select have the advantage of not requiring any extra file - # descriptor, contrarily to epoll/kqueue (also, they require a single - # syscall). - if hasattr(selectors, 'PollSelector'): - _PopenSelector = selectors.PollSelector - else: - _PopenSelector = selectors.SelectSelector - - __all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "getstatusoutput", "getoutput", "check_output", "CalledProcessError", "DEVNULL"] @@ -449,6 +423,13 @@ "STD_ERROR_HANDLE", "SW_HIDE", "STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW"]) + class STARTUPINFO: + dwFlags = 0 + hStdInput = None + hStdOutput = None + hStdError = None + wShowWindow = 0 + class Handle(int): closed = False @@ -468,6 +449,23 @@ __del__ = Close __str__ = __repr__ +else: + import _posixsubprocess + import select + import selectors + + # 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) + + # poll/select have the advantage of not requiring any extra file + # descriptor, contrarily to epoll/kqueue (also, they require a single + # syscall). + if hasattr(selectors, 'PollSelector'): + _PopenSelector = selectors.PollSelector + else: + _PopenSelector = selectors.SelectSelector # This lists holds Popen instances for which the underlying process had not