Commit 0661727b authored by maruel@chromium.org's avatar maruel@chromium.org

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
parent b17b55be
# 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.
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment