| 356 | |
| 357 | @contextlib.contextmanager |
| 358 | def join(self): |
| 359 | assert self._workers or not self._queue.unfinished_tasks |
| 360 | ui_worker = click_threading.UiWorker() |
| 361 | self._shutdown_handlers.append(ui_worker.shutdown) |
| 362 | _echo = click.echo |
| 363 | |
| 364 | with ui_worker.patch_click(): |
| 365 | yield |
| 366 | |
| 367 | if not self._workers: |
| 368 | # Ugly hack, needed because ui_worker is not running. |
| 369 | click.echo = _echo |
| 370 | cli_logger.critical('Nothing to do.') |
| 371 | sys.exit(5) |
| 372 | |
| 373 | ui_worker.run() |
| 374 | self._queue.join() |
| 375 | for worker in self._workers: |
| 376 | worker.join() |
| 377 | |
| 378 | tasks_failed = next(self.num_failed_tasks) |
| 379 | tasks_done = next(self.num_done_tasks) |
| 380 | |
| 381 | if tasks_failed > 0: |
| 382 | cli_logger.error('{} out of {} tasks failed.' |
| 383 | .format(tasks_failed, tasks_done)) |
| 384 | sys.exit(1) |
| 385 | |
| 386 | def put(self, f): |
| 387 | return self._queue.put(f) |