| OLD | NEW |
| 1 # Copyright 2009 Google Inc. All Rights Reserved. | 1 # Copyright 2009 Google Inc. All Rights Reserved. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 return config_dir, env['entries'] | 542 return config_dir, env['entries'] |
| 543 | 543 |
| 544 | 544 |
| 545 class WorkItem(object): | 545 class WorkItem(object): |
| 546 """One work item.""" | 546 """One work item.""" |
| 547 # A list of string, each being a WorkItem name. | 547 # A list of string, each being a WorkItem name. |
| 548 requirements = [] | 548 requirements = [] |
| 549 # A unique string representing this work item. | 549 # A unique string representing this work item. |
| 550 name = None | 550 name = None |
| 551 | 551 |
| 552 def run(self, work_queue, options): | 552 def run(self, work_queue): |
| 553 """work_queue and options are passed as keyword arguments so they should be | 553 """work_queue is passed as keyword argument so it should be |
| 554 the last parameters of the function when you override it.""" | 554 the last parameters of the function when you override it.""" |
| 555 pass | 555 pass |
| 556 | 556 |
| 557 | 557 |
| 558 class ExecutionQueue(object): | 558 class ExecutionQueue(object): |
| 559 """Runs a set of WorkItem that have interdependencies and were WorkItem are | 559 """Runs a set of WorkItem that have interdependencies and were WorkItem are |
| 560 added as they are processed. | 560 added as they are processed. |
| 561 | 561 |
| 562 In gclient's case, Dependencies sometime needs to be run out of order due to | 562 In gclient's case, Dependencies sometime needs to be run out of order due to |
| 563 From() keyword. This class manages that all the required dependencies are run | 563 From() keyword. This class manages that all the required dependencies are run |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 654 |
| 655 def _flush_terminated_threads(self): | 655 def _flush_terminated_threads(self): |
| 656 """Flush threads that have terminated.""" | 656 """Flush threads that have terminated.""" |
| 657 running = self.running | 657 running = self.running |
| 658 self.running = [] | 658 self.running = [] |
| 659 for t in running: | 659 for t in running: |
| 660 if t.isAlive(): | 660 if t.isAlive(): |
| 661 self.running.append(t) | 661 self.running.append(t) |
| 662 else: | 662 else: |
| 663 t.join() | 663 t.join() |
| 664 t.kwargs['options'].stdout.full_flush() | 664 sys.stdout.full_flush() |
| 665 if self.progress: | 665 if self.progress: |
| 666 self.progress.update(1) | 666 self.progress.update(1) |
| 667 assert not t.item.name in self.ran | 667 assert not t.item.name in self.ran |
| 668 if not t.item.name in self.ran: | 668 if not t.item.name in self.ran: |
| 669 self.ran.append(t.item.name) | 669 self.ran.append(t.item.name) |
| 670 | 670 |
| 671 def _run_one_task(self, task_item, args, kwargs): | 671 def _run_one_task(self, task_item, args, kwargs): |
| 672 if self.jobs > 1: | 672 if self.jobs > 1: |
| 673 # Start the thread. | 673 # Start the thread. |
| 674 index = len(self.ran) + len(self.running) + 1 | 674 index = len(self.ran) + len(self.running) + 1 |
| 675 # Copy 'options'. | 675 new_thread = self._Worker(task_item, index, args, kwargs) |
| 676 task_kwargs = kwargs.copy() | |
| 677 task_kwargs['options'] = copy.copy(task_kwargs['options']) | |
| 678 new_thread = self._Worker(task_item, index, args, task_kwargs) | |
| 679 self.running.append(new_thread) | 676 self.running.append(new_thread) |
| 680 new_thread.start() | 677 new_thread.start() |
| 681 else: | 678 else: |
| 682 # Run the 'thread' inside the main thread. Don't try to catch any | 679 # Run the 'thread' inside the main thread. Don't try to catch any |
| 683 # exception. | 680 # exception. |
| 684 task_item.run(*args, **kwargs) | 681 task_item.run(*args, **kwargs) |
| 685 self.ran.append(task_item.name) | 682 self.ran.append(task_item.name) |
| 686 if self.progress: | 683 if self.progress: |
| 687 self.progress.update(1) | 684 self.progress.update(1) |
| 688 | 685 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 707 logging.info('Caught exception in thread %s' % self.item.name) | 704 logging.info('Caught exception in thread %s' % self.item.name) |
| 708 logging.info(str(sys.exc_info())) | 705 logging.info(str(sys.exc_info())) |
| 709 work_queue.exceptions.put(sys.exc_info()) | 706 work_queue.exceptions.put(sys.exc_info()) |
| 710 logging.info('Task %s done' % self.item.name) | 707 logging.info('Task %s done' % self.item.name) |
| 711 | 708 |
| 712 work_queue.ready_cond.acquire() | 709 work_queue.ready_cond.acquire() |
| 713 try: | 710 try: |
| 714 work_queue.ready_cond.notifyAll() | 711 work_queue.ready_cond.notifyAll() |
| 715 finally: | 712 finally: |
| 716 work_queue.ready_cond.release() | 713 work_queue.ready_cond.release() |
| OLD | NEW |