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

Method _query_dirty_workers

gunicorn/ctl/handlers.py:516–559  ·  view source on GitHub ↗

Query the dirty arbiter for worker information. Connects to the dirty arbiter socket and sends a status request. Returns: List of dirty worker info dicts, or empty list on error

(self)

Source from the content-addressed store, hash-verified

514 }
515
516 def _query_dirty_workers(self) -> list:
517 """
518 Query the dirty arbiter for worker information.
519
520 Connects to the dirty arbiter socket and sends a status request.
521
522 Returns:
523 List of dirty worker info dicts, or empty list on error
524 """
525 # Get socket path from arbiter object or environment
526 dirty_socket_path = None
527 if hasattr(self.arbiter, 'dirty_arbiter') and self.arbiter.dirty_arbiter:
528 dirty_socket_path = getattr(self.arbiter.dirty_arbiter, 'socket_path', None)
529 if not dirty_socket_path:
530 dirty_socket_path = os.environ.get('GUNICORN_DIRTY_SOCKET')
531 if not dirty_socket_path:
532 return []
533
534 try:
535 from gunicorn.dirty.protocol import DirtyProtocol
536
537 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
538 sock.settimeout(2.0)
539 sock.connect(dirty_socket_path)
540
541 # Send status request
542 request = {
543 "type": DirtyProtocol.MSG_TYPE_STATUS,
544 "id": "ctl-status-1",
545 }
546 DirtyProtocol.write_message(sock, request)
547
548 # Read response
549 response = DirtyProtocol.read_message(sock)
550 sock.close()
551
552 if response.get("type") == DirtyProtocol.MSG_TYPE_RESPONSE:
553 result = response.get("result", {})
554 return result.get("workers", [])
555
556 except Exception:
557 pass
558
559 return []
560
561 def help(self) -> dict:
562 """

Callers 1

show_allMethod · 0.95

Calls 6

getMethod · 0.45
settimeoutMethod · 0.45
connectMethod · 0.45
write_messageMethod · 0.45
read_messageMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected