New submission from Gabriel Mesquita Cangussu: The documentation of asyncio specifies that the methods connect_read_pipe and connect_write_pipe are available on Windows with the ProactorEventLoop. The documentation then says that those methods accept file-like objects on the pipe parameter. However, the methods doesn't seem to work with stdio or any disk file under Windows. The following example catches this problem:
import asyncio import sys class MyProtocol(asyncio.Protocol): def connection_made(self, transport): print('connection established') def data_received(self, data): print('received: {!r}'.format(data.decode())) def connection_lost(self, exc): print('lost connection') if sys.platform.startswith('win32'): loop = asyncio.ProactorEventLoop() else: loop = asyncio.SelectorEventLoop() coro = loop.connect_read_pipe(MyProtocol, sys.stdin) loop.run_until_complete(coro) loop.run_forever() loop.close() This code when executed on Ubuntu have the desired behavior, but under Windows 10 it gives OSError: [WinError 6] The handle is invalid. The complete output is this: c:\Users\Gabriel\Documents\Python Scripts>python async_pipe.py connection established Fatal read error on pipe transport protocol: <__main__.MyProtocol object at 0x000001970EB2FAC8> transport: <_ProactorReadPipeTransport fd=0> Traceback (most recent call last): File "C:\Program Files\Python35\lib\asyncio\proactor_events.py", line 195, in _loop_reading self._read_fut = self._loop._proactor.recv(self._sock, 4096) File "C:\Program Files\Python35\lib\asyncio\windows_events.py", line 425, in recv self._register_with_iocp(conn) File "C:\Program Files\Python35\lib\asyncio\windows_events.py", line 606, in _register_with_iocp _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0) OSError: [WinError 6] Identificador inválido lost connection I think that the documentation should state that there is no support for disk files and stdio with the methods in question and also state what exactly they support (an example would be nice). And, of course, better support for watching file descriptors on Windows on future Python releases would be nice. Thank you, Gabriel ---------- components: Windows, asyncio messages: 264043 nosy: Gabriel Mesquita Cangussu, gvanrossum, haypo, paul.moore, steve.dower, tim.golden, yselivanov, zach.ware priority: normal severity: normal status: open title: ProactorEventLoop doesn't support stdin/stdout nor files with connect_read_pipe/connect_write_pipe type: behavior versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26832> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com