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

Method _handle_client

gunicorn/ctl/server.py:224–263  ·  view source on GitHub ↗

Handle client connection. Args: reader: asyncio StreamReader writer: asyncio StreamWriter

(self, reader, writer)

Source from the content-addressed store, hash-verified

222 pass
223
224 async def _handle_client(self, reader, writer):
225 """
226 Handle client connection.
227
228 Args:
229 reader: asyncio StreamReader
230 writer: asyncio StreamWriter
231 """
232 try:
233 while self._running:
234 try:
235 message = await asyncio.wait_for(
236 ControlProtocol.read_message_async(reader),
237 timeout=300.0 # 5 minute idle timeout
238 )
239 except asyncio.TimeoutError:
240 # Client idle too long, close connection
241 break
242 except asyncio.IncompleteReadError:
243 # Client disconnected
244 break
245 except Exception:
246 # Protocol error
247 break
248
249 # Process command
250 response = await self._dispatch(message)
251
252 # Send response
253 await ControlProtocol.write_message_async(writer, response)
254
255 except Exception as e:
256 if self.arbiter.log:
257 self.arbiter.log.debug("Control client error: %s", e)
258 finally:
259 writer.close()
260 try:
261 await writer.wait_closed()
262 except Exception:
263 pass
264
265 async def _dispatch(self, message: dict) -> dict:
266 """

Callers

nothing calls this directly

Calls 6

_dispatchMethod · 0.95
read_message_asyncMethod · 0.45
write_message_asyncMethod · 0.45
debugMethod · 0.45
closeMethod · 0.45
wait_closedMethod · 0.45

Tested by

no test coverage detected