0

我收到以下错误:

ERROR asyncio:base_events.py:1608 Exception in callback _SelectorSocketTransport._read_ready()

它发生在代码的这一点上。基本上在超时期间无法完成任务:

        """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 await fut
    
        if timeout <= 0:
            fut = ensure_future(fut, loop=loop)
    

                 if fut.done():
                return fut.result()
    
            fut.cancel()
            raise futures.TimeoutError()
    
        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:
                await waiter
            except futures.CancelledError:
                fut.remove_done_callback(cb)
                fut.cancel()
                raise
    
            if fut.done():
                return fut.result()
            else:
                fut.remove_done_callback(cb)
                # We must ensure that the task is not running
                # after wait_for() returns.
                # See https://bugs.python.org/issue32751
                await _cancel_and_wait(fut, loop=loop)
>               raise futures.TimeoutError()
E               concurrent.futures._base.TimeoutError

../../.pyenv/versions/3.7.3/lib/python3.7/asyncio/tasks.py:423: TimeoutError

最后,这会导致连接关闭:

  async def ensure_open(self) -> None:
        """
        Check that the WebSocket connection is open.
    
        Raise :exc:`~websockets.exceptions.ConnectionClosed` if it isn't.
    
        """
        # Handle cases from most common to least common for performance.
        if self.state is State.OPEN:
            # If self.transfer_data_task exited without a closing handshake,
            # self.close_connection_task may be closing the connection, going
            # straight from OPEN to CLOSED.
            if self.transfer_data_task.done():
                await asyncio.shield(self.close_connection_task)
                raise self.connection_closed_exc()
            else:
                return
    
        if self.state is State.CLOSED:
>           raise self.connection_closed_exc()
E           websockets.exceptions.ConnectionClosedError: code = 1011 (unexpected error), no reason

../../.pyenv/versions/3.7.3/envs/evse-test-stand/lib/python3.7/site-packages/websockets/protocol.py:803: ConnectionClosedError

因此,对我正在做的事情进行更多解释:我基本上尝试通过嵌入式系统上的 websocket 连接服务器。

我更改了超时值,但没有帮助。我对 websocket 如何工作的话题很陌生,所以经过一些研究,我真的不知道为什么会这样。

我很感激任何帮助:)

4

0 回答 0