Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: gclient_utils.py

Issue 6689023: Revert r80216 "Reapply r79779: "Removed gclient_utils.Popen() and use subprocess2's ..."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | subprocess2.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_utils.py
diff --git a/gclient_utils.py b/gclient_utils.py
index 733d43fca236727fb5afb5f584f9ced53c2a5543..97c8227c097370f2e933f759a5a268e752d72020 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -17,10 +17,13 @@ import time
import xml.dom.minidom
import xml.parsers.expat
-import subprocess2
-# Keep an alias for now.
-Popen = subprocess2.Popen
+def hack_subprocess():
+ """subprocess functions may throw exceptions when used in multiple threads.
+
+ See http://bugs.python.org/issue1731717 for more information.
+ """
+ subprocess._cleanup = lambda: None
class Error(Exception):
@@ -52,6 +55,32 @@ class CheckCallError(OSError, Error):
return out
+def Popen(args, **kwargs):
+ """Calls subprocess.Popen() with hacks to work around certain behaviors.
+
+ Ensure English outpout for svn and make it work reliably on Windows.
+ """
+ logging.debug(u'%s, cwd=%s' % (u' '.join(args), kwargs.get('cwd', '')))
+ if not 'env' in kwargs:
+ # It's easier to parse the stdout if it is always in English.
+ kwargs['env'] = os.environ.copy()
+ kwargs['env']['LANGUAGE'] = 'en'
+ if not 'shell' in kwargs:
+ # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for the
+ # executable, but shell=True makes subprocess on Linux fail when it's called
+ # with a list because it only tries to execute the first item in the list.
+ kwargs['shell'] = (sys.platform=='win32')
+ try:
+ return subprocess.Popen(args, **kwargs)
+ except OSError, e:
+ if e.errno == errno.EAGAIN and sys.platform == 'cygwin':
+ raise Error(
+ 'Visit '
+ 'http://code.google.com/p/chromium/wiki/CygwinDllRemappingFailure to '
+ 'learn how to fix this error; you need to rebase your cygwin dlls')
+ raise
+
+
def CheckCall(command, print_error=True, **kwargs):
"""Similar subprocess.check_call() but redirects stdout and
returns (stdout, stderr).
@@ -537,6 +566,7 @@ class ExecutionQueue(object):
def __init__(self, jobs, progress):
"""jobs specifies the number of concurrent tasks to allow. progress is a
Progress instance."""
+ hack_subprocess()
# Set when a thread is done or a new item is enqueued.
self.ready_cond = threading.Condition()
# Maximum number of concurrent tasks.
« no previous file with comments | « no previous file | subprocess2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698