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

Method run

gunicorn/asgi/websocket.py:100–126  ·  view source on GitHub ↗

Run the WebSocket ASGI application.

(self)

Source from the content-addressed store, hash-verified

98 self._data_event.set()
99
100 async def run(self):
101 """Run the WebSocket ASGI application."""
102 # Send initial connect event
103 await self._receive_queue.put({"type": "websocket.connect"})
104
105 # Start frame reading task
106 read_task = asyncio.create_task(self._read_frames())
107
108 try:
109 await self.app(self.scope, self._receive, self._send)
110 except Exception:
111 self.log.exception("Error in WebSocket ASGI application")
112 finally:
113 # Send close frame if not already closed
114 if not self.closed and self.accepted and not self._close_sent:
115 await self._send_close(CLOSE_INTERNAL_ERROR, "Application error")
116 # Wait for client's close response
117 try:
118 await asyncio.wait_for(self._close_event.wait(), timeout=5.0)
119 except asyncio.TimeoutError:
120 self.closed = True
121
122 read_task.cancel()
123 try:
124 await read_task
125 except asyncio.CancelledError:
126 pass
127
128 async def _receive(self):
129 """ASGI receive callable."""

Callers 1

_handle_websocketMethod · 0.95

Calls 6

_read_framesMethod · 0.95
_send_closeMethod · 0.95
putMethod · 0.80
appMethod · 0.45
exceptionMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected