Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 unique string representing this work item. | 482 # A unique string representing this work item. |
| 483 self._name = name | 483 self._name = name |
| 484 self.lock = threading.RLock() | 484 try: |
| 485 self.lock = threading.Lock() | |
|
Dirk Pranke
2011/10/12 23:24:32
Is changing from an RLock to a Lock intentional? A
M-A Ruel
2011/10/12 23:28:32
It's intentional, the code doesn't have any recurs
| |
| 486 except: # pylint: disable=W0702 | |
| 487 # On cygwin, it's throwing randomly. Hack and reuse the single | |
| 488 # sys.stdout.lock. Yep you read it right. Single lock. | |
| 489 self.lock = sys.stdout.lock | |
|
Dirk Pranke
2011/10/12 23:24:32
Can we wrap this in an if sys.platform == 'cygwin'
M-A Ruel
2011/10/12 23:28:32
done
| |
| 485 | 490 |
| 486 def run(self, work_queue): | 491 def run(self, work_queue): |
| 487 """work_queue is passed as keyword argument so it should be | 492 """work_queue is passed as keyword argument so it should be |
| 488 the last parameters of the function when you override it.""" | 493 the last parameters of the function when you override it.""" |
| 489 pass | 494 pass |
| 490 | 495 |
| 491 @property | 496 @property |
| 492 def name(self): | 497 def name(self): |
| 493 return self._name | 498 return self._name |
| 494 | 499 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 logging.info('Caught exception in thread %s' % self.item.name) | 663 logging.info('Caught exception in thread %s' % self.item.name) |
| 659 logging.info(str(sys.exc_info())) | 664 logging.info(str(sys.exc_info())) |
| 660 work_queue.exceptions.put(sys.exc_info()) | 665 work_queue.exceptions.put(sys.exc_info()) |
| 661 logging.info('_Worker.run(%s) done' % self.item.name) | 666 logging.info('_Worker.run(%s) done' % self.item.name) |
| 662 | 667 |
| 663 work_queue.ready_cond.acquire() | 668 work_queue.ready_cond.acquire() |
| 664 try: | 669 try: |
| 665 work_queue.ready_cond.notifyAll() | 670 work_queue.ready_cond.notifyAll() |
| 666 finally: | 671 finally: |
| 667 work_queue.ready_cond.release() | 672 work_queue.ready_cond.release() |
| OLD | NEW |