(self)
| 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).""" |
nothing calls this directly
no test coverage detected