Skip to content

Commit bc11359

Browse files
committed
This doesn't do much except avoids acquiring the lock twice per iteration.
1 parent 7eee7d4 commit bc11359

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/psij/executors/local.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,14 @@ def register(self, entry: _ProcessEntry) -> None:
136136

137137
def run(self) -> None:
138138
logger.debug('Started {}'.format(self))
139+
done: List[_ProcessEntry] = []
139140
while True:
140141
with self._lock:
142+
for entry in done:
143+
del self._jobs[entry.job]
141144
jobs = dict(self._jobs)
142-
143145
try:
144-
self._check_processes(jobs)
146+
done = self._check_processes(jobs)
145147
except Exception as ex:
146148
logger.error('Error polling for process status', ex)
147149
with self._cvar:
@@ -164,7 +166,7 @@ def _handle_sigchld(self) -> None:
164166
# there is really no telling what else could go wrong.
165167
logger.debug('Exception in Condition.notify_all()')
166168

167-
def _check_processes(self, jobs: Dict[Job, _ProcessEntry]) -> None:
169+
def _check_processes(self, jobs: Dict[Job, _ProcessEntry]) -> List[_ProcessEntry]:
168170
done: List[_ProcessEntry] = []
169171

170172
for entry in jobs.values():
@@ -178,13 +180,10 @@ def _check_processes(self, jobs: Dict[Job, _ProcessEntry]) -> None:
178180
entry.out = out
179181
done.append(entry)
180182

181-
if len(done) > 0:
182-
with self._lock:
183-
for entry in done:
184-
del self._jobs[entry.job]
183+
for entry in done:
184+
entry.executor._process_done(entry)
185185

186-
for entry in done:
187-
entry.executor._process_done(entry)
186+
return done
188187

189188
def cancel(self, job: Job) -> None:
190189
with self._lock:

0 commit comments

Comments
 (0)