Redirect stdout and stderr to file to avoid deadlock

This commit is contained in:
Simon Wörner 2017-11-24 20:28:18 +01:00
parent 2374224cdf
commit f08b473c50

View file

@ -8,7 +8,9 @@ import os
import platform import platform
import sys import sys
from distutils.spawn import find_executable from distutils.spawn import find_executable
from subprocess import PIPE, Popen from subprocess import Popen
import shutil
from tempfile import TemporaryFile
SEARCH_PATHS = [ SEARCH_PATHS = [
os.path.join("python", "tidy"), os.path.join("python", "tidy"),
@ -101,6 +103,25 @@ def _get_virtualenv_script_dir():
return "bin" return "bin"
def _process_exec(args):
with TemporaryFile() as out:
with TemporaryFile() as err:
process = Popen(args, stdout=out, stderr=err)
process.wait()
if process.returncode:
print('"%s" failed with error code %d:' % ('" "'.join(args), process.returncode))
print('Output:')
out.seek(0)
shutil.copyfileobj(out, sys.stdout)
print('Error:')
err.seek(0)
shutil.copyfileobj(err, sys.stdout)
sys.exit()
def wpt_path(is_firefox, topdir, *paths): def wpt_path(is_firefox, topdir, *paths):
if is_firefox: if is_firefox:
rel = os.path.join("..", "testing", "web-platform") rel = os.path.join("..", "testing", "web-platform")
@ -135,16 +156,8 @@ def _activate_virtualenv(topdir, is_firefox):
if not virtualenv: if not virtualenv:
sys.exit("Python virtualenv is not installed. Please install it prior to running mach.") sys.exit("Python virtualenv is not installed. Please install it prior to running mach.")
process = Popen( _process_exec([virtualenv, "-p", python, "--system-site-packages", virtualenv_path])
[virtualenv, "-p", python, "--system-site-packages", virtualenv_path],
stdout=PIPE,
stderr=PIPE
)
process.wait()
if process.returncode:
out, err = process.communicate()
print('Python virtualenv failed to execute properly:')
sys.exit('Output: %s\nError: %s' % (out, err))
# We want to upgrade pip when virtualenv created for the first time # We want to upgrade pip when virtualenv created for the first time
need_pip_upgrade = True need_pip_upgrade = True
@ -174,12 +187,7 @@ def _activate_virtualenv(topdir, is_firefox):
if not pip: if not pip:
sys.exit("Python pip is either not installed or not found in virtualenv.") sys.exit("Python pip is either not installed or not found in virtualenv.")
process = Popen([pip, "install", "-q", "-I", "-U", "pip"], stdout=PIPE, stderr=PIPE) _process_exec([pip, "install", "-q", "-I", "-U", "pip"])
process.wait()
if process.returncode:
out, err = process.communicate()
print('Pip failed to upgrade itself properly:')
sys.exit('Output: %s\nError: %s' % (out, err))
for req_rel_path in requirements_paths: for req_rel_path in requirements_paths:
req_path = os.path.join(topdir, req_rel_path) req_path = os.path.join(topdir, req_rel_path)
@ -196,12 +204,7 @@ def _activate_virtualenv(topdir, is_firefox):
if not pip: if not pip:
sys.exit("Python pip is either not installed or not found in virtualenv.") sys.exit("Python pip is either not installed or not found in virtualenv.")
process = Popen([pip, "install", "-q", "-I", "-r", req_path], stdout=PIPE, stderr=PIPE) _process_exec([pip, "install", "-q", "-I", "-r", req_path])
process.wait()
if process.returncode:
out, err = process.communicate()
print('Pip failed to execute properly:')
sys.exit('Output: %s\nError: %s' % (out, err))
open(marker_path, 'w').close() open(marker_path, 'w').close()