Fix delegator leaky file handles

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2018-10-22 10:13:34 -04:00
parent 4c8617237c
commit e375eb3eaa
2 changed files with 59 additions and 6 deletions
+15 -6
View File
@@ -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
@@ -234,14 +235,22 @@ class Command(object):
"""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
@@ -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