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

Method _safe_write

gunicorn/asgi/protocol.py:730–747  ·  view source on GitHub ↗

Write data to transport, handling connection errors gracefully. Catches exceptions that occur when the client has disconnected: - OSError with errno EPIPE, ECONNRESET, ENOTCONN - RuntimeError when transport is closing/closed - AttributeError when transport is None

(self, data)

Source from the content-addressed store, hash-verified

728 self._flow_control.resume_writing()
729
730 def _safe_write(self, data):
731 """Write data to transport, handling connection errors gracefully.
732
733 Catches exceptions that occur when the client has disconnected:
734 - OSError with errno EPIPE, ECONNRESET, ENOTCONN
735 - RuntimeError when transport is closing/closed
736 - AttributeError when transport is None
737
738 These are silently ignored since the client is already gone.
739 """
740 try:
741 self.transport.write(data)
742 except OSError as e:
743 if e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ENOTCONN):
744 self.log.exception("Socket error writing response.")
745 except (RuntimeError, AttributeError):
746 # Transport is closing/closed or None
747 pass
748
749 async def _handle_connection(self):
750 """Main request handling loop using callback-based parser.

Callers 4

sendMethod · 0.95
_send_informationalMethod · 0.95
_send_bodyMethod · 0.95
_send_error_responseMethod · 0.95

Calls 2

writeMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected