| 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 |
| 36 |
| 37 atexit.register(SignalWorkerThreads) |
| 38 |
| 39 |
| 23 def Worker(): | 40 def Worker(): |
| 24 global TASK_QUEUE | 41 global TASK_QUEUE |
| 25 while True: | 42 while True: |
| 26 function, args, kwargs, result_semaphore = TASK_QUEUE.get() | 43 try: |
| 44 task = TASK_QUEUE.get() |
| 45 if not task: |
| 46 return |
| 47 except TypeError: |
| 48 # According to http://bugs.python.org/issue14623, this is a harmless bug |
| 49 # in python 2.7 which won't be fixed. |
| 50 # The exception is raised on daemon threads when python interpreter is |
| 51 # shutting down. |
| 52 return |
| 53 |
| 54 function, args, kwargs, result_semaphore = task |
| 27 try: | 55 try: |
| 28 function(*args, **kwargs) | 56 function(*args, **kwargs) |
| 29 except: | 57 except: |
| 30 pass | 58 pass |
| 31 finally: | 59 finally: |
| 32 # Signal one task is done in case of exception. | 60 # Signal one task is done in case of exception. |
| 33 result_semaphore.release() | 61 result_semaphore.release() |
| 34 | 62 |
| 35 | 63 |
| 36 def RunTasks(tasks): | 64 def RunTasks(tasks): |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 review_url = None | 582 review_url = None |
| 555 reviewers = None | 583 reviewers = None |
| 556 line_content = blame.line_content | 584 line_content = blame.line_content |
| 557 message = blame.message | 585 message = blame.message |
| 558 | 586 |
| 559 result = Result(suspected_cl, revision_url, component_name, author, reason, | 587 result = Result(suspected_cl, revision_url, component_name, author, reason, |
| 560 review_url, reviewers, line_content, message) | 588 review_url, reviewers, line_content, message) |
| 561 result_list.append(result) | 589 result_list.append(result) |
| 562 | 590 |
| 563 return result_list | 591 return result_list |
| OLD | NEW |