def refactor()

in bowler/tool.py [0:0]


    def refactor(self, items: Sequence[str], *a, **k) -> None:
        """Refactor a list of files and directories."""

        for dir_or_file in sorted(items):
            if os.path.isdir(dir_or_file):
                self.refactor_dir(dir_or_file)
            else:
                self.queue_work(Filename(dir_or_file))

        children: List[multiprocessing.Process] = []
        if self.in_process:
            self.queue.put(None)
            self.refactor_queue()
        else:
            child_count = max(1, min(self.NUM_PROCESSES, self.queue_count))
            self.log_debug(f"starting {child_count} processes")
            for i in range(child_count):
                child = multiprocessing.Process(target=self.refactor_queue)
                child.start()
                children.append(child)
                self.queue.put(None)

        results_count = 0

        while True:
            try:
                filename, hunks, exc = self.results.get_nowait()
                results_count += 1

                if exc:
                    self.log_error(f"{type(exc).__name__}: {exc}")
                    if exc.__cause__:
                        self.log_error(
                            f"  {type(exc.__cause__).__name__}: {exc.__cause__}"
                        )
                    if isinstance(exc, BowlerException) and exc.hunks:
                        diff = "\n".join("\n".join(hunk) for hunk in exc.hunks)
                        self.log_error(f"Generated transform:\n{diff}")
                    self.exceptions.append(exc)
                else:
                    self.log_debug(f"results: got {len(hunks)} hunks for {filename}")
                    self.process_hunks(filename, hunks)

            except Empty:
                if self.queue.empty() and results_count == self.queue_count:
                    break

                elif not self.in_process and not any(
                    child.is_alive() for child in children
                ):
                    self.log_debug(f"child processes stopped without consuming work")
                    break

                else:
                    time.sleep(0.05)

            except BowlerQuit:
                for child in children:
                    child.terminate()
                break

        self.log_debug(f"all children stopped and all diff hunks processed")