[issue26832] ProactorEventLoop doesn't support stdin/stdout nor files with connect_read_pipe/connect_write_pipe
Min RK
report at bugs.python.org
Wed Feb 23 05:03:17 EST 2022
Min RK <benjaminrk at gmail.com> added the comment:
It appears that connect_read_pipe also doesn't accept pipes returned by `os.pipe`. If that's the case, what _does_ ProactorEventLoop.connect_read_pipe accept? I haven't been able to find any examples of `connect_read_pipe` that work on Windows, and every connect_read_pipe call in the cpython test suite appears to be skipped on win32. Should it still be raising NotImplementedError on ProactorEventLoop?
I think the error handling could be better (I only get logged errors, nothing I can catch/handle). It seems like `connect_read_pipe` itself should raise when it fails to register the pipe with IOCP. If that's not feasible, connection_lost/transport.close should probably be triggered, but it isn't with Python 3.9, at least.
Example that works on posix, but seems to fail with non-catchable errors with ProactorEventLoop:
```
import asyncio
import os
import sys
class PipeProtocol(asyncio.Protocol):
def __init__(self):
self.finished = asyncio.Future()
def connection_made(self, transport):
print("connection made", file=sys.stderr)
self.transport = transport
def connection_lost(self, exc):
print("connection lost", exc, file=sys.stderr)
self.finished.set_result(None)
def data_received(self, data):
print("data received", data, file=sys.stderr)
self.handler(data)
def eof_received(self):
print("eof received", file=sys.stderr)
self.finished.set_result(None)
async def test():
r, w = os.pipe()
rf = os.fdopen(r, 'r')
x, p = await asyncio.get_running_loop().connect_read_pipe(PipeProtocol, rf)
await asyncio.sleep(1)
print("writing")
os.write(w, b'asdf')
await asyncio.sleep(2)
print("closing")
os.close(w)
await asyncio.wait([p.finished], timeout=3)
x.close()
if __name__ == "__main__":
asyncio.run(test())
```
----------
nosy: +minrk
versions: +Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26832>
_______________________________________
More information about the Python-bugs-list
mailing list