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

Method _dispatch

gunicorn/ctl/server.py:265–300  ·  view source on GitHub ↗

Dispatch command to appropriate handler. Args: message: Request message dict Returns: Response dictionary

(self, message: dict)

Source from the content-addressed store, hash-verified

263 pass
264
265 async def _dispatch(self, message: dict) -> dict:
266 """
267 Dispatch command to appropriate handler.
268
269 Args:
270 message: Request message dict
271
272 Returns:
273 Response dictionary
274 """
275 request_id = message.get("id", 0)
276 command = message.get("command", "").strip()
277 args = message.get("args", [])
278
279 if not command:
280 return make_error_response(request_id, "Empty command")
281
282 try:
283 # Parse command (e.g., "show workers" or "worker add 2")
284 parts = shlex.split(command)
285 if args:
286 parts.extend(str(a) for a in args)
287
288 if not parts:
289 return make_error_response(request_id, "Empty command")
290
291 # Route to handler
292 result = self._execute_command(parts)
293 return make_response(request_id, result)
294
295 except ValueError as e:
296 return make_error_response(request_id, f"Invalid argument: {e}")
297 except Exception as e:
298 if self.arbiter.log:
299 self.arbiter.log.exception("Command error")
300 return make_error_response(request_id, f"Command failed: {e}")
301
302 def _execute_command(self, parts: list) -> dict: # pylint: disable=too-many-return-statements
303 """

Callers 1

_handle_clientMethod · 0.95

Calls 5

_execute_commandMethod · 0.95
make_error_responseFunction · 0.90
make_responseFunction · 0.90
getMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected