OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 codecs | 7 import codecs |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import Queue | 10 import Queue |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 self.kwargs = kwargs | 738 self.kwargs = kwargs |
739 self.daemon = True | 739 self.daemon = True |
740 | 740 |
741 def run(self): | 741 def run(self): |
742 """Runs in its own thread.""" | 742 """Runs in its own thread.""" |
743 logging.debug('_Worker.run(%s)' % self.item.name) | 743 logging.debug('_Worker.run(%s)' % self.item.name) |
744 work_queue = self.kwargs['work_queue'] | 744 work_queue = self.kwargs['work_queue'] |
745 try: | 745 try: |
746 self.item.run(*self.args, **self.kwargs) | 746 self.item.run(*self.args, **self.kwargs) |
747 except KeyboardInterrupt: | 747 except KeyboardInterrupt: |
748 logging.info('Caught KeyboardInterrupt in thread %s' % self.item.name) | 748 logging.info('Caught KeyboardInterrupt in thread %s', self.item.name) |
749 logging.info(str(sys.exc_info())) | 749 logging.info(str(sys.exc_info())) |
750 work_queue.exceptions.put(sys.exc_info()) | 750 work_queue.exceptions.put(sys.exc_info()) |
751 raise | 751 raise |
752 except Exception: | 752 except Exception: |
753 # Catch exception location. | 753 # Catch exception location. |
754 logging.info('Caught exception in thread %s' % self.item.name) | 754 logging.info('Caught exception in thread %s', self.item.name) |
755 logging.info(str(sys.exc_info())) | 755 logging.info(str(sys.exc_info())) |
756 work_queue.exceptions.put(sys.exc_info()) | 756 work_queue.exceptions.put(sys.exc_info()) |
757 finally: | 757 finally: |
758 logging.info('_Worker.run(%s) done' % self.item.name) | 758 logging.info('_Worker.run(%s) done', self.item.name) |
759 work_queue.ready_cond.acquire() | 759 work_queue.ready_cond.acquire() |
760 try: | 760 try: |
761 work_queue.ready_cond.notifyAll() | 761 work_queue.ready_cond.notifyAll() |
762 finally: | 762 finally: |
763 work_queue.ready_cond.release() | 763 work_queue.ready_cond.release() |
764 | 764 |
765 | 765 |
766 def GetEditor(git, git_editor=None): | 766 def GetEditor(git, git_editor=None): |
767 """Returns the most plausible editor to use. | 767 """Returns the most plausible editor to use. |
768 | 768 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 | 868 |
869 Python on OSX 10.6 raises a NotImplementedError exception. | 869 Python on OSX 10.6 raises a NotImplementedError exception. |
870 """ | 870 """ |
871 try: | 871 try: |
872 import multiprocessing | 872 import multiprocessing |
873 return multiprocessing.cpu_count() | 873 return multiprocessing.cpu_count() |
874 except: # pylint: disable=W0702 | 874 except: # pylint: disable=W0702 |
875 # Mac OS 10.6 only | 875 # Mac OS 10.6 only |
876 # pylint: disable=E1101 | 876 # pylint: disable=E1101 |
877 return int(os.sysconf('SC_NPROCESSORS_ONLN')) | 877 return int(os.sysconf('SC_NPROCESSORS_ONLN')) |
OLD | NEW |