def _get_process(self): debug.dbg('Start environment subprocess %s', self._executable) parso_path = sys.modules['parso'].__file__ args = ( self._executable, _MAIN_PATH, os.path.dirname(os.path.dirname(parso_path)), '.'.join(str(x) for x in sys.version_info[:3]), ) process = GeneralizedPopen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, # Use system default buffering on Python 2 to improve performance # (this is already the case on Python 3). bufsize=-1) self._stderr_queue = Queue() self._stderr_thread = t = Thread(target=_enqueue_output, args=(process.stderr, self._stderr_queue)) t.daemon = True t.start() # Ensure the subprocess is properly cleaned up when the object # is garbage collected. self._cleanup_callable = weakref.finalize(self, _cleanup_process, process, t) return process
def _get_version(self): try: process = GeneralizedPopen([self.executable, '--version'], stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() retcode = process.poll() if retcode: raise InvalidPythonEnvironment() except OSError: raise InvalidPythonEnvironment() # Until Python 3.4 wthe version string is part of stderr, after that # stdout. output = stdout + stderr match = re.match(br'Python (\d+)\.(\d+)\.(\d+)', output) if match is None: raise InvalidPythonEnvironment("--version not working") return _VersionInfo(*[int(m) for m in match.groups()])
def _process(self): parso_path = sys.modules['parso'].__file__ args = (self._executable, _MAIN_PATH, os.path.dirname(os.path.dirname(parso_path))) return GeneralizedPopen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, )
def _process(self): parso_path = sys.modules['parso'].__file__ args = (self._executable, _MAIN_PATH, os.path.dirname(os.path.dirname(parso_path))) return GeneralizedPopen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, # Use system default buffering on Python 2 to improve performance # (this is already the case on Python 3). bufsize=-1)
def _get_process(self): debug.dbg('Start environment subprocess %s', self._executable) parso_path = sys.modules['parso'].__file__ args = ( self._executable, _MAIN_PATH, os.path.dirname(os.path.dirname(parso_path)), '.'.join(str(x) for x in sys.version_info[:3]), ) # Use explicit envionment to ensure reliable results (#1540) env = {} if os.name == 'nt': # if SYSTEMROOT (or case variant) exists in environment, # ensure it goes to subprocess for k, v in os.environ.items(): if 'SYSTEMROOT' == k.upper(): env.update({k: os.environ[k]}) break # don't risk multiple entries process = GeneralizedPopen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, # Use system default buffering on Python 2 to improve performance # (this is already the case on Python 3). bufsize=-1, env=env) self._stderr_queue = Queue() self._stderr_thread = t = Thread(target=_enqueue_output, args=(process.stderr, self._stderr_queue)) t.daemon = True t.start() # Ensure the subprocess is properly cleaned up when the object # is garbage collected. self._cleanup_callable = weakref.finalize(self, _cleanup_process, process, t) return process