Return an asyncio exception handler that silences Windows WinError 10054 noise from connection cleanup (ConnectionResetError in _ProactorBasePipeTransport._call_connection_lost), which is harmless but verbose on Python/Windows when a remote host force-closes a socket.
(log)
| 313 | |
| 314 | |
| 315 | def _make_exception_handler(log): |
| 316 | """Return an asyncio exception handler that silences Windows WinError 10054 |
| 317 | noise from connection cleanup (ConnectionResetError in |
| 318 | _ProactorBasePipeTransport._call_connection_lost), which is harmless but |
| 319 | verbose on Python/Windows when a remote host force-closes a socket.""" |
| 320 | def handler(loop, context): |
| 321 | exc = context.get("exception") |
| 322 | cb = context.get("handle") or context.get("source_traceback", "") |
| 323 | if ( |
| 324 | isinstance(exc, ConnectionResetError) |
| 325 | and "_call_connection_lost" in str(cb) |
| 326 | ): |
| 327 | return # suppress: benign Windows socket cleanup race |
| 328 | log.error("[asyncio] %s", context.get("message", context)) |
| 329 | if exc: |
| 330 | loop.default_exception_handler(context) |
| 331 | return handler |
| 332 | |
| 333 | |
| 334 | async def _run(config): |