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

Unified Diff: gclient_utils.py

Issue 1730014: Revert r45652 and r45653. It broke the single file export... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 10 years, 8 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 | « gclient.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_utils.py
===================================================================
--- gclient_utils.py (revision 45659)
+++ gclient_utils.py (working copy)
@@ -17,14 +17,11 @@
import errno
import logging
import os
-import Queue
import re
import stat
import subprocess
import sys
import time
-import threading
-import traceback
import xml.dom.minidom
import xml.parsers.expat
@@ -356,106 +353,3 @@
execfile(config_path, env)
config_dir = os.path.dirname(config_path)
return config_dir, env['entries']
-
-
-class ThreadPool:
- """A thread pool class that lets one schedule jobs on many worker threads."""
-
- def __init__(self, threads=1):
- self._threads = threads
- self._queue = Queue.Queue()
- self._jobs_left = 0
- self._condition = threading.Condition()
- self._workers = []
-
- class Worker(threading.Thread):
- """Internal worker class that executes jobs from the ThreadPool queue."""
-
- def __init__(self, pool):
- threading.Thread.__init__(self)
- self._pool = pool
- self._done = False
- self.exceptions = []
-
- def Done(self):
- """Terminates the worker threads."""
- self._done = True
-
- def run(self):
- """Executes jobs from the pool's queue."""
- while not self._done:
- f = self._pool._queue.get()
- try:
- try:
- f(self)
- except Exception, e:
- # Catch all exceptions, otherwise we can't join the thread. Print
- # the backtrace now, but keep the exception so that we can raise it
- # on the main thread.
- type, value, tb = sys.exc_info()
- traceback.print_exception(type, value, tb)
- self.exceptions.append(e)
- finally:
- self._pool._JobDone()
-
- def _AddJobToQueue(self, job):
- self._condition.acquire()
- self._queue.put(job)
- self._jobs_left += 1
- self._condition.release()
-
- def _JobDone(self):
- self._condition.acquire()
- try:
- assert self._jobs_left
- self._jobs_left -= 1
- if self._jobs_left == 0:
- self._condition.notify()
- finally:
- self._condition.release()
-
- def _JoinQueue(self):
- self._condition.acquire()
- try:
- while self._jobs_left:
- self._condition.wait()
- finally:
- self._condition.release()
-
- def Start(self):
- """Starts the thread pool. Spawns worker threads."""
- assert not self._workers
- for i in xrange(0, self._threads):
- worker = self.Worker(self)
- self._workers.append(worker)
- worker.start()
-
- def Stop(self):
- """Stops the thread pool. Joins all worker threads."""
- assert self._workers
- for i in xrange(0, len(self._workers)):
- wrapped = lambda thread: thread.Done()
- self._AddJobToQueue(wrapped)
- self._JoinQueue()
- for worker in self._workers:
- worker.join()
- try:
- for worker in self._workers:
- for e in worker.exceptions:
- # If we collected exceptions, raise them now.
- raise e
- finally:
- self._workers = []
-
- def AddJob(self, function):
- """Adds a job to the queue.
-
- A job is a simple closure, that will get executed on one of the worker
- threads."""
- wrapped = lambda worker: function()
- self._AddJobToQueue(wrapped)
-
- def WaitJobs(self):
- """Waits for all jobs to be completed."""
- assert self._workers
- self._JoinQueue()
« no previous file with comments | « gclient.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698