aio-libs/aiohttp · error · RuntimeError
Named Pipes only available in proactor loop under windows
Error message
Named Pipes only available in proactor loop under windows
What it means
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.
Source
Thrown at aiohttp/connector.py:1756
def __init__(
self,
path: str,
force_close: bool = False,
keepalive_timeout: _SENTINEL | float | None = sentinel,
limit: int = 100,
limit_per_host: int = 0,
) -> None:
super().__init__(
force_close=force_close,
keepalive_timeout=keepalive_timeout,
limit=limit,
limit_per_host=limit_per_host,
)
if not isinstance(
self._loop,
asyncio.ProactorEventLoop, # type: ignore[attr-defined]
):
raise RuntimeError(
"Named Pipes only available in proactor loop under windows"
)
self._path = path
@property
def path(self) -> str:
"""Path to the named pipe."""
return self._path
async def _create_connection(
self, req: ClientRequest, traces: list["Trace"], timeout: "ClientTimeout"
) -> ResponseHandler:
try:
async with ceil_timeout(
timeout.sock_connect, ceil_threshold=timeout.ceil_threshold
):
_, proto = await self._loop.create_pipe_connection( # type: ignore[attr-defined]
self._factory, self._pathView on GitHub (pinned to c0ef574e29)
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.
Example fix
# before (Linux)
connector = aiohttp.NamedPipeConnector(r'\\\\.\\pipe\\foo')
# after
import sys, asyncio
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
connector = aiohttp.NamedPipeConnector(r'\\\\.\\pipe\\foo')
else:
raise RuntimeError('Named pipes are Windows-only') Defensive patterns
Strategy: validation
Validate before calling
import sys, asyncio
def can_use_named_pipe() -> bool:
if sys.platform != 'win32':
return False
return isinstance(asyncio.get_event_loop(), asyncio.ProactorEventLoop) Prevention
- 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.
When it happens
Trigger: Instantiating NamedPipeConnector on Linux/macOS, or on Windows while a SelectorEventLoop is active, or inside an environment that forces the selector loop.
Common situations: 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.
Related errors
- Named Pipes only available in proactor loop under windows
- Cannot initialize a TLS-in-TLS connection to host {req.url.h
- Session and connector have to use same event loop
- keepalive_timeout cannot be set if force_close is True
- Connector is closed.
AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04).
Data as JSON: /data/errors/11b7d509991059ba.json.
Report an issue: GitHub.