Esempio n. 1
0
    def join(self):
        assert self._workers or not self._queue.unfinished_tasks
        ui_worker = click_threading.UiWorker()
        self._shutdown_handlers.append(ui_worker.shutdown)
        _echo = click.echo

        with ui_worker.patch_click():
            yield

            if not self._workers:
                # Ugly hack, needed because ui_worker is not running.
                click.echo = _echo
                cli_logger.critical('Nothing to do.')
                sys.exit(5)

            ui_worker.run()
            self._queue.join()
            for worker in self._workers:
                worker.join()

        tasks_failed = next(self.num_failed_tasks)
        tasks_done = next(self.num_done_tasks)

        if tasks_failed > 0:
            cli_logger.error('{} out of {} tasks failed.'
                             .format(tasks_failed, tasks_done))
            sys.exit(1)
Esempio n. 2
0
    def cli():

        ui = click_threading.UiWorker()

        def target():
            click.prompt('two')
            ui.shutdown()

        click.prompt('one')

        with ui.patch_click():
            t = click_threading.Thread(target=target)
            t.start()
            ui.run()

        click.prompt('three')
        t.join()