Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior with standard input #22

Open
pbk20191 opened this issue Apr 22, 2024 · 0 comments
Open

Inconsistent behavior with standard input #22

pbk20191 opened this issue Apr 22, 2024 · 0 comments

Comments

@pbk20191
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant