Skip to content

Error using EchoAgent on windows regarding asyncio #3

@THZthz

Description

@THZthz

It seems asyncio only support running the script on unix-like environment? I got OSError: [WinError 6] The handle is invalid running it on windows. Seems the default proactor loop is designed for sockets, not for pipes like standard I/O.

Here is the example output:

(agent-client-protocol-python) PS D:\dev\projects\agent-client-protocol-python> python .\examples\agent.py
Exception in callback _ProactorReadPipeTransport._loop_reading()
handle: <Handle _ProactorReadPipeTransport._loop_reading()>
Traceback (most recent call last):
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 306, in _loop_reading
    self._read_fut = self._loop._proactor.recv_into(self._sock, self._data)
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\windows_events.py", line 497, in recv_into
    self._register_with_iocp(conn)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\windows_events.py", line 710, 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\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 316, in _loop_reading
    self._fatal_error(exc, 'Fatal read error on pipe transport')
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 132, in _fatal_error
    self._force_close(exc)
    ~~~~~~~~~~~~~~~~~^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 135, in _force_close
    if self._empty_waiter is not None and not self._empty_waiter.done():
       ^^^^^^^^^^^^^^^^^^
AttributeError: '_ProactorReadPipeTransport' object has no attribute '_empty_waiter'
Traceback (most recent call last):
  File "D:\dev\projects\agent-client-protocol-python\examples\agent.py", line 50, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "D:\dev\projects\agent-client-protocol-python\examples\agent.py", line 42, in main
    reader, writer = await stdio_streams()
                     ^^^^^^^^^^^^^^^^^^^^^
  File "D:\dev\projects\agent-client-protocol-python\src\acp\stdio.py", line 46, in stdio_streams
    transport, _ = await loop.connect_write_pipe(lambda: write_protocol, sys.stdout)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 1713, in connect_write_pipe
    transport = self._make_write_pipe_transport(pipe, protocol, waiter)
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 681, in _make_write_pipe_transport
    return _ProactorWritePipeTransport(self,
                                       sock, protocol, waiter, extra)
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 441, in __init__
    self._read_fut = self._loop._proactor.recv(self._sock, 16)
                     ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\windows_events.py", line 484, in recv
    self._register_with_iocp(conn)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\tanhz1\AppData\Roaming\uv\python\cpython-3.13.7-windows-x86_64-none\Lib\asyncio\windows_events.py", line 710, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 6] The handle is invalid

Can you fix it? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions