MCPcopy
hub / github.com/benoitc/gunicorn / run

Method run

gunicorn/workers/gthread.py:369–416  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

367 raise
368
369 def run(self):
370 # Register the method queue with the poller
371 self.poller.register(self.method_queue.fileno(),
372 selectors.EVENT_READ,
373 self.method_queue.run_callbacks)
374
375 # Start accepting connections
376 self.set_accept_enabled(True)
377
378 while self.alive:
379 # Notify the arbiter we are alive
380 self.notify()
381
382 # Check if we can accept more connections
383 can_accept = self.nr_conns < self.worker_connections
384 if can_accept != self._accepting:
385 self.set_accept_enabled(can_accept)
386
387 # Wait for events (unified event loop - no futures.wait())
388 self.wait_for_and_dispatch_events(timeout=1.0)
389
390 if not self.is_parent_alive():
391 break
392
393 # Handle keepalive and pending connection timeouts
394 self.murder_keepalived()
395 self.murder_pending()
396
397 # Graceful shutdown: stop accepting but handle existing connections
398 self.set_accept_enabled(False)
399
400 # Wait for in-flight connections within grace period
401 graceful_timeout = time.monotonic() + self.cfg.graceful_timeout
402 while self.nr_conns > 0:
403 time_remaining = max(graceful_timeout - time.monotonic(), 0)
404 if time_remaining == 0:
405 break
406 self.wait_for_and_dispatch_events(timeout=time_remaining)
407 self.murder_keepalived()
408 self.murder_pending()
409
410 # Cleanup
411 self.tpool.shutdown(wait=False)
412 self.poller.close()
413 self.method_queue.close()
414
415 for s in self.sockets:
416 s.close()
417
418 def finish_request(self, conn, fs):
419 """Handle completion of a request (called via method_queue on main thread)."""

Callers

nothing calls this directly

Calls 9

set_accept_enabledMethod · 0.95
is_parent_aliveMethod · 0.95
murder_keepalivedMethod · 0.95
murder_pendingMethod · 0.95
filenoMethod · 0.45
notifyMethod · 0.45
shutdownMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected