From 0661727bdcf50fef9aae8ed08d52095b1baa2a69 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Thu, 4 Nov 2010 13:50:50 +0000 Subject: [PATCH] Reduce the chances for gclient to throw an exception in subprocess module. Python standard library is not thread safe. Work around it by leaking a bit. The problem is particularly visible on python 2.4. TEST=none BUG=60623 Review URL: http://codereview.chromium.org/4465001 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@65048 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient_utils.py | 25 ++++++++++++------------- tests/gclient_utils_test.py | 4 ++-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/gclient_utils.py b/gclient_utils.py index d0fbb1ef7..5ab1ed509 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -1,16 +1,6 @@ -# Copyright 2009 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Generic utils.""" @@ -28,6 +18,14 @@ import xml.dom.minidom import xml.parsers.expat +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): """gclient exception class.""" pass @@ -573,6 +571,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. diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py index 934e4bb99..aa759ffb0 100755 --- a/tests/gclient_utils_test.py +++ b/tests/gclient_utils_test.py @@ -30,8 +30,8 @@ class GclientUtilsUnittest(GclientUtilBase): 'ParseXML', 'Popen', 'PrintableObject', 'RemoveDirectory', 'SoftClone', 'SplitUrlRevision', 'SyntaxErrorToError', 'WorkItem', - 'errno', 'logging', 'os', 'Queue', 're', 'stat', 'subprocess', - 'sys','threading', 'time', 'xml', + 'errno', 'hack_subprocess', 'logging', 'os', 'Queue', 're', 'stat', + 'subprocess', 'sys','threading', 'time', 'xml', ] # If this test fails, you should add the relevant test. self.compareMembers(gclient_utils, members)