| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 obj = new_fileobj.output_buffers[index] = [''] | 355 obj = new_fileobj.output_buffers[index] = [''] |
| 356 else: | 356 else: |
| 357 obj = new_fileobj.output_buffers[index] | 357 obj = new_fileobj.output_buffers[index] |
| 358 finally: | 358 finally: |
| 359 new_fileobj.lock.release() | 359 new_fileobj.lock.release() |
| 360 | 360 |
| 361 # Continue lockless. | 361 # Continue lockless. |
| 362 obj[0] += out | 362 obj[0] += out |
| 363 while '\n' in obj[0]: | 363 while '\n' in obj[0]: |
| 364 line, remaining = obj[0].split('\n', 1) | 364 line, remaining = obj[0].split('\n', 1) |
| 365 new_fileobj.old_annotated_write('%d>%s\n' % (index, line)) | 365 if line: |
| 366 new_fileobj.old_annotated_write('%d>%s\n' % (index, line)) |
| 366 obj[0] = remaining | 367 obj[0] = remaining |
| 367 | 368 |
| 368 def full_flush(): | 369 def full_flush(): |
| 369 """Flush buffered output.""" | 370 """Flush buffered output.""" |
| 370 orphans = [] | 371 orphans = [] |
| 371 new_fileobj.lock.acquire() | 372 new_fileobj.lock.acquire() |
| 372 try: | 373 try: |
| 373 # Detect threads no longer existing. | 374 # Detect threads no longer existing. |
| 374 indexes = (getattr(t, 'index', None) for t in threading.enumerate()) | 375 indexes = (getattr(t, 'index', None) for t in threading.enumerate()) |
| 375 indexes = filter(None, indexes) | 376 indexes = filter(None, indexes) |
| 376 for index in new_fileobj.output_buffers: | 377 for index in new_fileobj.output_buffers: |
| 377 if not index in indexes: | 378 if not index in indexes: |
| 378 orphans.append((index, new_fileobj.output_buffers[index][0])) | 379 orphans.append((index, new_fileobj.output_buffers[index][0])) |
| 379 for orphan in orphans: | 380 for orphan in orphans: |
| 380 del new_fileobj.output_buffers[orphan[0]] | 381 del new_fileobj.output_buffers[orphan[0]] |
| 381 finally: | 382 finally: |
| 382 new_fileobj.lock.release() | 383 new_fileobj.lock.release() |
| 383 | 384 |
| 384 # Don't keep the lock while writting. Will append \n when it shouldn't. | 385 # Don't keep the lock while writting. Will append \n when it shouldn't. |
| 385 for orphan in orphans: | 386 for orphan in orphans: |
| 386 new_fileobj.old_annotated_write('%d>%s\n' % (orphan[0], orphan[1])) | 387 if orphan[1]: |
| 388 new_fileobj.old_annotated_write('%d>%s\n' % (orphan[0], orphan[1])) |
| 387 | 389 |
| 388 new_fileobj.write = annotated_write | 390 new_fileobj.write = annotated_write |
| 389 new_fileobj.full_flush = full_flush | 391 new_fileobj.full_flush = full_flush |
| 390 return new_fileobj | 392 return new_fileobj |
| 391 | 393 |
| 392 | 394 |
| 393 def CheckCallAndFilter(args, stdout=None, filter_fn=None, | 395 def CheckCallAndFilter(args, stdout=None, filter_fn=None, |
| 394 print_stdout=None, call_filter_on_first_line=False, | 396 print_stdout=None, call_filter_on_first_line=False, |
| 395 **kwargs): | 397 **kwargs): |
| 396 """Runs a command and calls back a filter function if needed. | 398 """Runs a command and calls back a filter function if needed. |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 logging.info('Caught exception in thread %s' % self.item.name) | 691 logging.info('Caught exception in thread %s' % self.item.name) |
| 690 logging.info(str(sys.exc_info())) | 692 logging.info(str(sys.exc_info())) |
| 691 work_queue.exceptions.put(sys.exc_info()) | 693 work_queue.exceptions.put(sys.exc_info()) |
| 692 logging.info('Task %s done' % self.item.name) | 694 logging.info('Task %s done' % self.item.name) |
| 693 | 695 |
| 694 work_queue.ready_cond.acquire() | 696 work_queue.ready_cond.acquire() |
| 695 try: | 697 try: |
| 696 work_queue.ready_cond.notifyAll() | 698 work_queue.ready_cond.notifyAll() |
| 697 finally: | 699 finally: |
| 698 work_queue.ready_cond.release() | 700 work_queue.ready_cond.release() |
| OLD | NEW |