Skip to content

Commit

Permalink
Use a dynamic timeout to wait for the optimal time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glandos authored and tilgovi committed Jan 30, 2014
1 parent 89a178a commit d76bab4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,15 @@ def sleep(self):
Sleep until PIPE is readable or we timeout.
A readable PIPE means a signal occurred.
"""
if self.WORKERS:
oldest = min(w.tmp.last_update() for w in self.WORKERS.values())
timeout = self.timeout - (time.time() - oldest)
# The timeout can be reached, so don't wait for a negative value
timeout = max(timeout, 1.0)
else:
timeout = 1.0
try:
ready = select.select([self.PIPE[0]], [], [], 1.0)
ready = select.select([self.PIPE[0]], [], [], timeout)
if not ready[0]:
return
while os.read(self.PIPE[0], 1):
Expand Down

0 comments on commit d76bab4

Please sign in to comment.