diff --git a/pipenv/vendor/delegator.py b/pipenv/vendor/delegator.py index d15aeb9783..3ffb2e31ca 100644 --- a/pipenv/vendor/delegator.py +++ b/pipenv/vendor/delegator.py @@ -178,6 +178,7 @@ def run(self, block=True, binary=False, cwd=None, env=None): # Use subprocess. if self.blocking: popen_kwargs = self._default_popen_kwargs.copy() + del popen_kwargs["stdin"] popen_kwargs["universal_newlines"] = not binary if cwd: popen_kwargs["cwd"] = cwd @@ -234,14 +235,22 @@ def block(self): """Blocks until process is complete.""" if self._uses_subprocess: # consume stdout and stderr - try: - stdout, stderr = self.subprocess.communicate() - self.__out = stdout - self.__err = stderr - except ValueError: - pass # Don't read from finished subprocesses. + if self.blocking: + try: + stdout, stderr = self.subprocess.communicate() + self.__out = stdout + self.__err = stderr + except ValueError: + pass # Don't read from finished subprocesses. + else: + self.subprocess.stdin.close() + self.std_out.close() + self.std_err.close() + self.subprocess.wait() else: + self.subprocess.sendeof() self.subprocess.wait() + self.subprocess.proc.stdout.close() def pipe(self, command, timeout=None, cwd=None): """Runs the current command and passes its output to the next diff --git a/tasks/vendoring/patches/vendor/delegator-close-filehandles.patch b/tasks/vendoring/patches/vendor/delegator-close-filehandles.patch new file mode 100644 index 0000000000..ac63825c35 --- /dev/null +++ b/tasks/vendoring/patches/vendor/delegator-close-filehandles.patch @@ -0,0 +1,44 @@ +diff --git a/pipenv/vendor/delegator.py b/pipenv/vendor/delegator.py +index 0c140cad..3ffb2e31 100644 +--- a/pipenv/vendor/delegator.py ++++ b/pipenv/vendor/delegator.py +@@ -178,6 +178,7 @@ class Command(object): + # Use subprocess. + if self.blocking: + popen_kwargs = self._default_popen_kwargs.copy() ++ del popen_kwargs["stdin"] + popen_kwargs["universal_newlines"] = not binary + if cwd: + popen_kwargs["cwd"] = cwd +@@ -233,18 +234,23 @@ class Command(object): + def block(self): + """Blocks until process is complete.""" + if self._uses_subprocess: +- self.subprocess.stdin.close() + # consume stdout and stderr +- try: +- stdout, stderr = self.subprocess.communicate() +- self.__out = stdout +- self.__err = stderr +- except ValueError: +- pass # Don't read from finished subprocesses. ++ if self.blocking: ++ try: ++ stdout, stderr = self.subprocess.communicate() ++ self.__out = stdout ++ self.__err = stderr ++ except ValueError: ++ pass # Don't read from finished subprocesses. ++ else: ++ self.subprocess.stdin.close() ++ self.std_out.close() ++ self.std_err.close() ++ self.subprocess.wait() + else: + self.subprocess.sendeof() +- self.subprocess.proc.stdout.close() + self.subprocess.wait() ++ self.subprocess.proc.stdout.close() + + def pipe(self, command, timeout=None, cwd=None): + """Runs the current command and passes its output to the next