{"id":"11b7d509991059ba","repo":"aio-libs/aiohttp","slug":"named-pipes-only-available-in-proactor-loop-under","errorCode":null,"errorMessage":"Named Pipes only available in proactor loop under windows","messagePattern":"Named Pipes only available in proactor loop under windows","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"aiohttp/connector.py","lineNumber":1756,"sourceCode":"    def __init__(\n        self,\n        path: str,\n        force_close: bool = False,\n        keepalive_timeout: _SENTINEL | float | None = sentinel,\n        limit: int = 100,\n        limit_per_host: int = 0,\n    ) -> None:\n        super().__init__(\n            force_close=force_close,\n            keepalive_timeout=keepalive_timeout,\n            limit=limit,\n            limit_per_host=limit_per_host,\n        )\n        if not isinstance(\n            self._loop,\n            asyncio.ProactorEventLoop,  # type: ignore[attr-defined]\n        ):\n            raise RuntimeError(\n                \"Named Pipes only available in proactor loop under windows\"\n            )\n        self._path = path\n\n    @property\n    def path(self) -> str:\n        \"\"\"Path to the named pipe.\"\"\"\n        return self._path\n\n    async def _create_connection(\n        self, req: ClientRequest, traces: list[\"Trace\"], timeout: \"ClientTimeout\"\n    ) -> ResponseHandler:\n        try:\n            async with ceil_timeout(\n                timeout.sock_connect, ceil_threshold=timeout.ceil_threshold\n            ):\n                _, proto = await self._loop.create_pipe_connection(  # type: ignore[attr-defined]\n                    self._factory, self._path","sourceCodeStart":1738,"sourceCodeEnd":1774,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/connector.py#L1738-L1774","documentation":"Raised by NamedPipeConnector.__init__ when the running event loop is not a ProactorEventLoop. Windows named pipes are only implemented on the proactor loop, so on SelectorEventLoop (the default on non-Windows, or selected explicitly on Windows) the constructor refuses instead of failing later. This is a RuntimeError raised at construction time, before any request is attempted.","triggerScenarios":"Instantiating NamedPipeConnector on Linux/macOS, or on Windows while a SelectorEventLoop is active, or inside an environment that forces the selector loop.","commonSituations":"Cross-platform code that unconditionally builds a NamedPipeConnector. asyncio.get_event_loop() returning a selector loop in older Python on Windows. Tests running on a non-Windows CI runner.","solutions":["On Windows, set the proactor loop before constructing: `asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())`.","Only construct NamedPipeConnector on Windows after checking `sys.platform == 'win32'` and the loop type.","On non-Windows, use UnixConnector (Unix socket) or the default TCPConnector instead."],"exampleFix":"# before (Linux)\nconnector = aiohttp.NamedPipeConnector(r'\\\\\\\\.\\\\pipe\\\\foo')\n# after\nimport sys, asyncio\nif sys.platform == 'win32':\n    asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())\n    connector = aiohttp.NamedPipeConnector(r'\\\\\\\\.\\\\pipe\\\\foo')\nelse:\n    raise RuntimeError('Named pipes are Windows-only')","handlingStrategy":"validation","validationCode":"import sys, asyncio\n\ndef can_use_named_pipe() -> bool:\n    if sys.platform != 'win32':\n        return False\n    return isinstance(asyncio.get_event_loop(), asyncio.ProactorEventLoop)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set WindowsProactorEventLoopPolicy() at startup if you intend to use named pipes.","Guard NamedPipeConnector construction behind sys.platform == 'win32'.","Provide a Unix-socket fallback for cross-platform code paths."],"tags":["connector","named-pipe","windows","event-loop","platform"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}