Skip to content

Process.stdin.[write&drain] succeeds after the pipe is closed #84

@gschaffner

Description

@gschaffner

Hi! On Winloop, but not on stdlib's default event loop or on uvloop, Process.stdin.write + Process.stdin.drain is succeeding after the pipe is closed:

import asyncio
import subprocess
import sys

import winloop


async def main() -> None:
    process = await asyncio.create_subprocess_exec(
        sys.executable, "-c", "", stdin=subprocess.PIPE
    )
    assert process.stdin is not None
    # Wait for the other end of the pipe to be closed:
    await process.wait()
    # Confirm that the IO manager knows that the pipe was closed:
    assert process.stdin.is_closing()
    # Therefore one of these should raise:
    process.stdin.write(b"foo")  # raises on uvloop
    await process.stdin.drain()  # raises on stdlib
    # But neither raises on Winloop currently! However, on Winloop they will raise if
    # called subsequently:
    # await process.stdin.drain()


# asyncio.run(main())
asyncio.run(main(), loop_factory=winloop.new_event_loop)

Winloop version: 0.3.0

Python version: CPython 3.13.7

The stdlib implementation has a conditional checkpoint in drain() which handles this case:

https://github.com/python/cpython/blob/v3.14.0/Lib/asyncio/streams.py#L375-L378

Metadata

Metadata

Assignees

Labels

Programmers WantedAdditional Programmers wanted for writing a fix or helping with the review process.bugSomething isn't workinghelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions