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

Side by Side Diff: gclient_utils.py

Issue 8174014: Stop modifiying requirements out of thread and generate it instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix the lack of constant ordering in GClientSmokeBoth.testMultiSolutionsJobs Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic utils.""" 5 """Generic utils."""
6 6
7 import errno 7 import errno
8 import logging 8 import logging
9 import os 9 import os
10 import Queue 10 import Queue
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 raise 472 raise
473 return method(self, *args, **kwargs) 473 return method(self, *args, **kwargs)
474 finally: 474 finally:
475 self.lock.release() 475 self.lock.release()
476 return inner 476 return inner
477 477
478 478
479 class WorkItem(object): 479 class WorkItem(object):
480 """One work item.""" 480 """One work item."""
481 def __init__(self, name): 481 def __init__(self, name):
482 # A list of string, each being a WorkItem name.
483 self._requirements = set()
484 # A unique string representing this work item. 482 # A unique string representing this work item.
485 self._name = name 483 self._name = name
486 self.lock = threading.RLock() 484 self.lock = threading.RLock()
487 485
488 @lockedmethod
489 def run(self, work_queue): 486 def run(self, work_queue):
490 """work_queue is passed as keyword argument so it should be 487 """work_queue is passed as keyword argument so it should be
491 the last parameters of the function when you override it.""" 488 the last parameters of the function when you override it."""
492 pass 489 pass
493 490
494 @property 491 @property
495 def name(self): 492 def name(self):
496 return self._name 493 return self._name
497 494
498 @property
499 @lockedmethod
500 def requirements(self):
501 return tuple(self._requirements)
502
503 @lockedmethod
504 def add_requirement(self, new):
505 self._requirements.add(new)
506
507 495
508 class ExecutionQueue(object): 496 class ExecutionQueue(object):
509 """Runs a set of WorkItem that have interdependencies and were WorkItem are 497 """Runs a set of WorkItem that have interdependencies and were WorkItem are
510 added as they are processed. 498 added as they are processed.
511 499
512 In gclient's case, Dependencies sometime needs to be run out of order due to 500 In gclient's case, Dependencies sometime needs to be run out of order due to
513 From() keyword. This class manages that all the required dependencies are run 501 From() keyword. This class manages that all the required dependencies are run
514 before running each one. 502 before running each one.
515 503
516 Methods of this class are thread safe. 504 Methods of this class are thread safe.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 logging.info('Caught exception in thread %s' % self.item.name) 658 logging.info('Caught exception in thread %s' % self.item.name)
671 logging.info(str(sys.exc_info())) 659 logging.info(str(sys.exc_info()))
672 work_queue.exceptions.put(sys.exc_info()) 660 work_queue.exceptions.put(sys.exc_info())
673 logging.info('_Worker.run(%s) done' % self.item.name) 661 logging.info('_Worker.run(%s) done' % self.item.name)
674 662
675 work_queue.ready_cond.acquire() 663 work_queue.ready_cond.acquire()
676 try: 664 try:
677 work_queue.ready_cond.notifyAll() 665 work_queue.ready_cond.notifyAll()
678 finally: 666 finally:
679 work_queue.ready_cond.release() 667 work_queue.ready_cond.release()
OLDNEW
« no previous file with comments | « gclient.py ('k') | tests/gclient_smoketest.py » ('j') | tests/gclient_smoketest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698