Skip to content

Inconsistent behavior with standard input #22

@pbk20191

Description

@pbk20191

I have my simple console echoing script. (python3.12)
If I run this using pycharm's run configuration this works normally echoing the console input back to stdout. However any other running configuration fails. e.g) vscode, python3 my.py ... etc

However, if I use Path('CONIN$').open instead of os.dup any case fails with the same exception.

import asyncio
import sys
from io import TextIOWrapper, FileIO
from typing import TextIO

import winloop
from sys import stdin
import os
from pathlib import Path

async def main():
    loop = asyncio.get_running_loop()
    reader = asyncio.StreamReader(loop=loop)
    
    with FileIO(os.dup(sys.stdin.fileno())) as fileInput:
    # with Path("CONIN$").open() as fileInput:
        transport, protocol = await loop.connect_read_pipe(
            lambda : asyncio.StreamReaderProtocol(stream_reader=reader,loop=loop),
            pipe=fileInput
        )
        try:
            while not reader.at_eof():
                line = (await reader.readline()).decode().rstrip()
                print(line)
        finally:
            transport.close()
if __name__ == '__main__':    
    asyncio.run(main(), debug=True, loop_factory=winloop.new_event_loop)
(.venv) C:\Users\pbk\PycharmProjects\pythonProject>.\.venv\Scripts\python.exe foo.py
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "winloop\\loop.pyx", line 1556, in winloop.loop.Loop.run_until_complete
  File "C:\Users\pbk\PycharmProjects\pythonProject\foo.py", line 21, in main
    transport, protocol = await loop.connect_read_pipe(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "winloop\\loop.pyx", line 2889, in connect_read_pipe
  File "winloop\\loop.pyx", line 2882, in winloop.loop.Loop.connect_read_pipe
  File "winloop\\handles/pipe.pyx", line 133, in winloop.loop.ReadUnixTransport._open
  File "winloop\\handles/pipe.pyx", line 35, in winloop.loop.__pipe_open
IsADirectoryError: [Errno 21] illegal operation on a directory

IsADirectoryError is not a correct error for this situation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions