Description
Trying to convert a multiprocessing.Pipe
to a PipeSendStream
/PipeReceiveStream
pair as I try to make my own multiprocessing
wrapper. This is on windows 10, python 3.8.5, trio 0.17.
import trio
from trio._windows_pipes import PipeReceiveStream, PipeSendStream
from multiprocessing import Process, Pipe, Event
def echo(recv_pipe, send_pipe, event):
bytes = recv_pipe.recv_bytes()
print('received', flush=True)
event.set()
send_pipe.send_bytes(bytes)
print('sent', flush=True)
async def main():
recv_pipe, send_pipe = Pipe()
event = Event()
proc = Process(target=echo, args=(recv_pipe, send_pipe, event), daemon=True)
proc.start()
send_stream = PipeSendStream(send_pipe.fileno())
recv_stream = PipeReceiveStream(recv_pipe.fileno())
await send_stream.send_all(b"Hello World")
event.wait()
response = await recv_stream.receive_some()
print(response, flush=True)
print("done", flush=True)
if __name__ == "__main__":
trio.run(main)
Trio then crashes when trying to receive the data. The event, or some kind of work/sleep to delay the main process, is crucial to triggering the bug.
received
sent
Traceback (most recent call last):
File "C:\redacted\site-packages\trio\_core\_run.py", line 2068, in unrolled_run
runner.io_manager.process_events(events)
File "C:\redacted\site-packages\trio\_core\_io_windows.py", line 516, in process_events
waiter = self._overlapped_waiters.pop(entry.lpOverlapped)
KeyError: <cdata 'OVERLAPPED *' 0x000001EDFA33D220>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\redacted\site-packages\trio\_core\_run.py", line 1236, in guest_tick
timeout = self.unrolled_run_next_send.send(self.unrolled_run_gen)
File "C:\redacted\site-packages\outcome\_sync.py", line 91, in send
return gen.send(self.value)
File "C:\redacted\site-packages\trio\_core\_run.py", line 2226, in unrolled_run
raise TrioInternalError("internal error in Trio - please file a bug!") from exc
trio.TrioInternalError: internal error in Trio - please file a bug!
Tk shutdown. Outcome: Value(None)
Process finished with exit code -1
Apparently IOCP successfully received it, but waking up the task fails. My debugger shows that on "C:\redacted\site-packages\trio_core_io_windows.py", line 516, in process_events, self._overlapped_waiters
contains a single entry <cdata 'OVERLAPPED *' owning 32 bytes>
whereas entry.lpOverlapped
is <cdata 'OVERLAPPED *' 0x000002302343F9A0>
, which does not compare equal and leads to the KeyError
.
It's hard for me to tell if I am doing something wrong while passing these handles around, or if I am trying to use unsupported behavior, or if it is really a Trio bug!