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() |
| 486 except: # pylint: disable=W0702 |
| 487 if sys.platform != 'cygwin': |
| 488 raise |
| 489 # On cygwin, it's throwing randomly. Hack and reuse the single |
| 490 # sys.stdout.lock. Yep you read it right. Single lock. |
| 491 self.lock = sys.stdout.lock |
485 | 492 |
486 def run(self, work_queue): | 493 def run(self, work_queue): |
487 """work_queue is passed as keyword argument so it should be | 494 """work_queue is passed as keyword argument so it should be |
488 the last parameters of the function when you override it.""" | 495 the last parameters of the function when you override it.""" |
489 pass | 496 pass |
490 | 497 |
491 @property | 498 @property |
492 def name(self): | 499 def name(self): |
493 return self._name | 500 return self._name |
494 | 501 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 logging.info('Caught exception in thread %s' % self.item.name) | 665 logging.info('Caught exception in thread %s' % self.item.name) |
659 logging.info(str(sys.exc_info())) | 666 logging.info(str(sys.exc_info())) |
660 work_queue.exceptions.put(sys.exc_info()) | 667 work_queue.exceptions.put(sys.exc_info()) |
661 logging.info('_Worker.run(%s) done' % self.item.name) | 668 logging.info('_Worker.run(%s) done' % self.item.name) |
662 | 669 |
663 work_queue.ready_cond.acquire() | 670 work_queue.ready_cond.acquire() |
664 try: | 671 try: |
665 work_queue.ready_cond.notifyAll() | 672 work_queue.ready_cond.notifyAll() |
666 finally: | 673 finally: |
667 work_queue.ready_cond.release() | 674 work_queue.ready_cond.release() |
OLD | NEW |