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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 print >> sys.stderr, 'Was deadlocked' | 473 print >> sys.stderr, 'Was deadlocked' |
474 raise | 474 raise |
475 return method(self, *args, **kwargs) | 475 return method(self, *args, **kwargs) |
476 finally: | 476 finally: |
477 self.lock.release() | 477 self.lock.release() |
478 return inner | 478 return inner |
479 | 479 |
480 | 480 |
481 class WorkItem(object): | 481 class WorkItem(object): |
482 """One work item.""" | 482 """One work item.""" |
483 # On cygwin, creating a lock throwing randomly when nearing ~100 locks. | |
484 # As a workaround, use a single lock. Yep you read it right. Single lock for | |
485 # all the 100 objects. | |
486 lock = threading.Lock() | |
487 | |
483 def __init__(self, name): | 488 def __init__(self, name): |
484 # A unique string representing this work item. | 489 # A unique string representing this work item. |
485 self._name = name | 490 self._name = name |
486 try: | |
487 self.lock = threading.Lock() | |
488 except: # pylint: disable=W0702 | |
489 if sys.platform != 'cygwin': | |
490 raise | |
491 # On cygwin, it's throwing randomly. Hack and reuse the single | |
492 # sys.stdout.lock. Yep you read it right. Single lock. | |
493 self.lock = sys.stdout.lock | |
Dirk Pranke
2011/10/19 19:40:45
so what happens if threading.Lock() fails an excep
M-A Ruel
2011/10/19 19:47:56
The problem that I started seeing is that while th
| |
494 | 491 |
495 def run(self, work_queue): | 492 def run(self, work_queue): |
496 """work_queue is passed as keyword argument so it should be | 493 """work_queue is passed as keyword argument so it should be |
497 the last parameters of the function when you override it.""" | 494 the last parameters of the function when you override it.""" |
498 pass | 495 pass |
499 | 496 |
500 @property | 497 @property |
501 def name(self): | 498 def name(self): |
502 return self._name | 499 return self._name |
503 | 500 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 logging.info('Caught exception in thread %s' % self.item.name) | 664 logging.info('Caught exception in thread %s' % self.item.name) |
668 logging.info(str(sys.exc_info())) | 665 logging.info(str(sys.exc_info())) |
669 work_queue.exceptions.put(sys.exc_info()) | 666 work_queue.exceptions.put(sys.exc_info()) |
670 logging.info('_Worker.run(%s) done' % self.item.name) | 667 logging.info('_Worker.run(%s) done' % self.item.name) |
671 | 668 |
672 work_queue.ready_cond.acquire() | 669 work_queue.ready_cond.acquire() |
673 try: | 670 try: |
674 work_queue.ready_cond.notifyAll() | 671 work_queue.ready_cond.notifyAll() |
675 finally: | 672 finally: |
676 work_queue.ready_cond.release() | 673 work_queue.ready_cond.release() |
OLD | NEW |