[Python] How do I cleanly stop a sanic server without getting errors related to websocket...

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have a python sanic website - I'm using pywebview to display it - when I close the pywebview window, I have a watcher which is doing an "app.stop"

    that works beautifully except I always get this error:

    Srv 0 10:21:39 ERROR: Error closing websocket connection
    Traceback (most recent call last):
    File "/opt/homebrew/lib/python3.13/site-packages/sanic/server/websockets/impl.py", line 422, in auto_close_connection
    self.io_proto.transport.write_eof()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
    File "uvloop/handles/stream.pyx", line 703, in uvloop.loop.UVStream.write_eof
    File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive
    RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0xa01669510>; the handler is closed


    and I can't find any way of getting rid of it - all the AI's I've asked give various "monkey patches" for sanic - which I'm not really ok with... but I'm not ok with the error either.

    Is there any way of gracefully shutting down sanic such that it nicely closes off everything without errors?

    Continue reading...

Compartilhe esta Página