Repository navigation
Open
Description
trio/_subprocess_platform/__init__.py imports asyncio.windows_utils. Since asyncio/__init__.py imports everything, importing trio on windows will result in importing the entire asyncio.
trio/src/trio/_subprocess_platform/__init__.py
Lines 96 to 117 in 4630d02
| elif os.name == "nt": | |
| import msvcrt | |
| # This isn't exported or documented, but it's also not | |
| # underscore-prefixed, and seems kosher to use. The asyncio docs | |
| # for 3.5 included an example that imported socketpair from | |
| # windows_utils (before socket.socketpair existed on Windows), and | |
| # when asyncio.windows_utils.socketpair was removed in 3.7, the | |
| # removal was mentioned in the release notes. | |
| from asyncio.windows_utils import pipe as windows_pipe | |
| from .._windows_pipes import PipeReceiveStream, PipeSendStream | |
| def create_pipe_to_child_stdin() -> tuple[PipeSendStream, int]: | |
| # for stdin, we want the write end (our end) to use overlapped I/O | |
| rh, wh = windows_pipe(overlapped=(False, True)) | |
| return PipeSendStream(wh), msvcrt.open_osfhandle(rh, os.O_RDONLY) | |
| def create_pipe_from_child_output() -> tuple[PipeReceiveStream, int]: | |
| # for stdout/err, it's the read end that's overlapped | |
| rh, wh = windows_pipe(overlapped=(True, False)) | |
| return PipeReceiveStream(rh), msvcrt.open_osfhandle(wh, 0) |
Problem
- Trio is positioned as an alternative to asyncio, importing asyncio itself is counterintuitive
- Importing the entire
asynciowould add about 100ms import time
Proposal
Implement windows pipe in trio style completely base on python 3.14 asyncio source. _windows_pipe.py and _windows_cffi.py already provide most api required, reimplementation should only cost about 100 to 200 lines I guess.
Metadata
Metadata
Assignees
Labels
No labels
Activity
A5rocks commentedon Oct 21, 2026
Yep this is around 10% of import cost. It's just annoying + Windows-only so I didn't change it previously. (PS try out
python -X importtimeto get a more accurate accounting)