This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: "connect_read_pipe" raises errors on Windows for STDIN
Type: Stage: resolved
Components: asyncio Versions: Python 3.9
Status: closed Resolution: duplicate
Dependencies: Superseder: ProactorEventLoop doesn't support stdin/stdout nor files with connect_read_pipe/connect_write_pipe
View: 26832
Assigned To: Nosy List: asvetlov, ivankravets, yselivanov
Priority: normal Keywords:

Created on 2021-03-17 12:43 by ivankravets, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (1)
msg388919 - (view) Author: Ivan Kravets (ivankravets) Date: 2021-03-17 12:43
Hi there,

It seems that "connect_read_pipe" is not implemented in ProactorEventLoop. Does it make sense to update docs in these places?

Or, this is a bug?

# The code to reproduce

import asyncio
import sys

async def read_stdin():
    reader = asyncio.StreamReader()
    protocol = asyncio.StreamReaderProtocol(reader)
    await asyncio.get_running_loop().connect_read_pipe(lambda: protocol, sys.stdin)
    while True:
        line = await reader.readline()
        print("stdin > ", line)

async def main():
    task = asyncio.create_task(read_stdin())
    await asyncio.sleep(5)

if __name__ == "__main__":

P.S: The "loop.add_reader()" raises "NotImplementedError" which is clear according to the docs.

Thanks in advance!

# Log

Exception in callback _ProactorReadPipeTransport._loop_reading()
handle: <Handle _ProactorReadPipeTransport._loop_reading()>
Traceback (most recent call last):
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 299, in _loop_reading
    self._read_fut = self._loop._proactor.recv(self._sock, 32768)
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 445, in recv
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 6] The handle is invalid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 80, in _run, *self._args)
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 309, in _loop_reading
    self._fatal_error(exc, 'Fatal read error on pipe transport')
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 131, in _fatal_error
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 134, in _force_close
    if self._empty_waiter is not None and not self._empty_waiter.done():
AttributeError: '_ProactorReadPipeTransport' object has no attribute '_empty_waiter'
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000002181B927A60>
Traceback (most recent call last):
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 116, in __del__
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 746, in call_soon
  File "C:\Users\USER\.platformio\python3\lib\asyncio\", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87694
2022-04-07 08:39:21kumaradityasetstatus: open -> closed
superseder: ProactorEventLoop doesn't support stdin/stdout nor files with connect_read_pipe/connect_write_pipe
resolution: duplicate
stage: resolved
2021-03-17 12:43:44ivankravetscreate