diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-04-17 21:53:25 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-17 21:53:25 +0900 |
| commit | af53987a332b2a50b21aa024a5bf24aaa504cc94 (patch) | |
| tree | 9a4509424c386d6d770092692f43eca413e7187c | |
| parent | 9f44ee4dd1761e12a25b63671dcc4b8ace1f2555 (diff) | |
| parent | 33b8f4334f493f2202b1964c28983b0570869956 (diff) | |
| download | sphinx-git-af53987a332b2a50b21aa024a5bf24aaa504cc94.tar.gz | |
Merge pull request #9097 from peterbell10/parallel-task-sleep
Remove unnecesary sleep when submitting parallel tasks
| -rw-r--r-- | sphinx/util/parallel.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index 7ad7f81e7..2d6b4bddb 100644 --- a/sphinx/util/parallel.py +++ b/sphinx/util/parallel.py @@ -105,7 +105,8 @@ class ParallelTasks: def join(self) -> None: try: while self._pworking: - self._join_one() + if not self._join_one(): + time.sleep(0.02) except Exception: # shutdown other child processes on failure self.terminate() @@ -119,7 +120,8 @@ class ParallelTasks: self._precvs.pop(tid) self._pworking -= 1 - def _join_one(self) -> None: + def _join_one(self) -> bool: + joined_any = False for tid, pipe in self._precvs.items(): if pipe.poll(): exc, logs, result = pipe.recv() @@ -131,15 +133,17 @@ class ParallelTasks: self._procs[tid].join() self._precvs.pop(tid) self._pworking -= 1 + joined_any = True break - else: - time.sleep(0.02) + while self._precvsWaiting and self._pworking < self.nproc: newtid, newprecv = self._precvsWaiting.popitem() self._precvs[newtid] = newprecv self._procs[newtid].start() self._pworking += 1 + return joined_any + def make_chunks(arguments: Sequence[str], nproc: int, maxbatch: int = 10) -> List[Any]: # determine how many documents to read in one go |
