python-trio / trio-asyncio

a re-implementation of the asyncio mainloop on top of Trio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Triopg crashes on windows due to "TypeError: need a stdlib socket"

touilleMan opened this issue · comments

TrioPG (trio wrapper of asyncpg based on trio-asyncio) is crashing on windows:

fut = <Task cancelled coro=<BaseEventLoop.create_connection() done, defined at C:\Python36-x64\lib\asyncio\base_events.py:681>>
timeout = 60
    @coroutine
    def wait_for(fut, timeout, *, loop=None):
        """Wait for the single Future or coroutine to complete, with timeout.
    
        Coroutine will be wrapped in Task.
    
        Returns result of the Future or coroutine.  When a timeout occurs,
        it cancels the task and raises TimeoutError.  To avoid the task
        cancellation, wrap it in shield().
    
        If the wait is cancelled, the task is also cancelled.
    
        This function is a coroutine.
        """
        if loop is None:
            loop = events.get_event_loop()
    
        if timeout is None:
            return (yield from fut)
    
        waiter = loop.create_future()
        timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
        cb = functools.partial(_release_waiter, waiter)
    
        fut = ensure_future(fut, loop=loop)
        fut.add_done_callback(cb)
    
        try:
            # wait until the future completes or the timeout
            try:
                yield from waiter
            except futures.CancelledError:
                fut.remove_done_callback(cb)
                fut.cancel()
                raise
    
            if fut.done():
                return fut.result()
            else:
                fut.remove_done_callback(cb)
                fut.cancel()
>               raise futures.TimeoutError()
E               concurrent.futures._base.TimeoutError
C:\Python36-x64\lib\asyncio\tasks.py:362: TimeoutError
------------------------------ Captured log call ------------------------------
base_events.py            1299 ERROR    Exception in default exception handler
Traceback (most recent call last):
  File "C:\Python36-x64\lib\asyncio\base_events.py", line 1293, in call_exception_handler
    self.default_exception_handler(context)
  File "C:\Python36-x64\lib\site-packages\trio_asyncio\async_.py", line 50, in default_exception_handler
    raise exception
  File "C:\Python36-x64\lib\site-packages\trio_asyncio\base.py", line 600, in _writer_loop
    await _wait_writable(fd)
  File "C:\Python36-x64\lib\site-packages\trio\_core\_io_windows.py", line 371, in wait_socket_writable
    await self._wait_socket("write", sock)
  File "C:\Python36-x64\lib\site-packages\trio\_core\_io_windows.py", line 350, in _wait_socket
    raise TypeError("need a stdlib socket")
TypeError: need a stdlib socket

see full CI logs here: https://ci.appveyor.com/project/touilleMan/triopg/build/job/mi2fi495cgvurjb8#L533

Error is the same than reported in #22

I suspect the fix is python-trio/trio#400 (i.e., fixing trio.hazmat.wait_socket_{read,writ}able so that they accept bare socket fds)

python-trio/trio#400 is now fixed in trio master, so hopefully this is fixed if you're using the latest trio from git? If you have a chance to check then it'd be nice to know :-)

@njsmith I'll wait for trio 0.7.0 to be released to restart this test (given I don't have windows dev environment, it's much simpler to just re-use the failing appveyor build which will install the lastest trio on pypi)