Skip to content

Commit

Permalink
Assume safe iteration of workers in the arbiter
Browse files Browse the repository at this point in the history
With reaping handled in the main execution context and kill_worker
delegating responsibility for cleanup to the reaping loop, iterate over
the workers dictionary everywhere else without concern for concurrent
modification.
  • Loading branch information
tilgovi committed Apr 21, 2020
1 parent 0d1752e commit f59ea64
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ def murder_workers(self):
"""
if not self.timeout:
return
workers = list(self.WORKERS.items())
for (pid, worker) in workers:
for (pid, worker) in self.WORKERS.items():
try:
if time.time() - worker.tmp.last_update() <= self.timeout:
continue
Expand Down Expand Up @@ -627,8 +626,7 @@ def kill_workers(self, sig):
Kill all workers with the signal `sig`
:attr sig: `signal.SIG*` value
"""
worker_pids = list(self.WORKERS.keys())
for pid in worker_pids:
for pid in self.WORKERS:
self.kill_worker(pid, sig)

def kill_worker(self, pid, sig):
Expand Down

0 comments on commit f59ea64

Please sign in to comment.