Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 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 import atexit | |
| 5 import cgi | 6 import cgi |
| 6 import ConfigParser | 7 import ConfigParser |
| 7 import json | 8 import json |
| 8 import os | 9 import os |
| 9 import Queue | 10 import Queue |
| 10 import threading | 11 import threading |
| 11 import time | 12 import time |
| 12 | 13 |
| 13 from common import utils | 14 from common import utils |
| 14 from result import Result | 15 from result import Result |
| 15 | 16 |
| 16 | 17 |
| 17 INFINITY = float('inf') | 18 INFINITY = float('inf') |
| 18 | 19 |
| 19 MAX_THREAD_NUMBER = 10 | 20 MAX_THREAD_NUMBER = 10 |
| 20 TASK_QUEUE = None | 21 TASK_QUEUE = None |
| 21 | 22 |
| 22 | 23 |
| 24 def SignalWorkerThreads(): | |
| 25 global TASK_QUEUE | |
| 26 if not TASK_QUEUE: | |
| 27 return | |
| 28 | |
| 29 for i in range(MAX_THREAD_NUMBER): | |
| 30 TASK_QUEUE.put(None) | |
| 31 | |
| 32 # Give worker threads a chance to exit. | |
| 33 # Workaround the harmless bug in python 2.7 below. | |
| 34 time.sleep(1) | |
| 35 print '%s is quitting' % threading.currentThread().name | |
| 36 | |
| 37 | |
| 38 atexit.register(SignalWorkerThreads) | |
| 39 | |
| 40 | |
| 23 def Worker(): | 41 def Worker(): |
| 24 global TASK_QUEUE | 42 global TASK_QUEUE |
| 25 while True: | 43 while True: |
| 26 function, args, kwargs, result_semaphore = TASK_QUEUE.get() | 44 try: |
|
stgao
2014/09/05 08:33:18
The exception is as below:
Exception in thread wo
| |
| 45 task = TASK_QUEUE.get() | |
| 46 if not task: | |
| 47 print '%s is quitting' % threading.currentThread().name | |
|
stgao
2014/09/05 08:33:18
I will revert the print before committing.
But I'd
| |
| 48 return | |
| 49 except TypeError: | |
| 50 # According to http://bugs.python.org/issue14623, this is a harmless bug | |
| 51 # in python 2.7 which won't be fixed. | |
| 52 # The exception is raised on daemon threads when python interpreter is | |
| 53 # shutting down. | |
| 54 return | |
| 55 | |
| 56 function, args, kwargs, result_semaphore = task | |
| 27 try: | 57 try: |
| 28 function(*args, **kwargs) | 58 function(*args, **kwargs) |
| 29 except: | 59 except: |
| 30 pass | 60 pass |
| 31 finally: | 61 finally: |
| 32 # Signal one task is done in case of exception. | 62 # Signal one task is done in case of exception. |
| 33 result_semaphore.release() | 63 result_semaphore.release() |
| 34 | 64 |
| 35 | 65 |
| 36 def RunTasks(tasks): | 66 def RunTasks(tasks): |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 review_url = None | 584 review_url = None |
| 555 reviewers = None | 585 reviewers = None |
| 556 line_content = blame.line_content | 586 line_content = blame.line_content |
| 557 message = blame.message | 587 message = blame.message |
| 558 | 588 |
| 559 result = Result(suspected_cl, revision_url, component_name, author, reason, | 589 result = Result(suspected_cl, revision_url, component_name, author, reason, |
| 560 review_url, reviewers, line_content, message) | 590 review_url, reviewers, line_content, message) |
| 561 result_list.append(result) | 591 result_list.append(result) |
| 562 | 592 |
| 563 return result_list | 593 return result_list |
| OLD | NEW |