Message264043
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 |
|
Date |
User |
Action |
Args |
2016-04-23 03:45:50 | Gabriel Mesquita Cangussu | set | recipients:
+ Gabriel Mesquita Cangussu, gvanrossum, paul.moore, vstinner, tim.golden, zach.ware, yselivanov, steve.dower |
2016-04-23 03:45:50 | Gabriel Mesquita Cangussu | set | messageid: <1461383150.45.0.258316694453.issue26832@psf.upfronthosting.co.za> |
2016-04-23 03:45:50 | Gabriel Mesquita Cangussu | link | issue26832 messages |
2016-04-23 03:45:49 | Gabriel Mesquita Cangussu | create | |
|