-
-
Notifications
You must be signed in to change notification settings - Fork 748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch WebSockets legacy implementation to Sans-I/O #1908
Comments
The documentation for this is here: https://websockets.readthedocs.io/en/stable/howto/sansio.html I don't remember how uvicorn integrates websockets so I'm not sure how much work it would take to upgrade to the Sans-I/O implementation. It would probably result in a more straightforward and testable design, though. As a reference, here's how websockets would use its own Sans-I/O layer: python-websockets/websockets#1245 You might find it helpful to look at Sanic's integration too: sanic-org/sanic#2158 I'm happy to answer questions and assist with reviews. |
Is it possible to send data as soon as I have available on the server with send_response? I want to send the headers, and then the body, and then more body, and maybe more body after... |
That can't be a WebSocket handshake response; it's unsupported in websockets. You aren't going to involve websockets anymore after sending such a response. You can ignore websockets and write directly to the network connection. If it makes the implementation cleaner or easier, you could call websockets's |
So I |
Well, If you want to rely as much as possible on public API to avoid breaking websockets' invariants, here's my recommendation:
If you find that annoying, you can just send what you want to the network and ignore exceptions thrown by websockets. |
I don't have bandwidth to do this. Whoever wants to do it, feel free to. I can review, give feedback, and also guide you on how to do it. |
@Kludex Happy to take this one! |
To implement SansIO shouldn't we use Server SansIO, but as the websocket is pinned in the requirements file the module is not available. Are there any breaking changes with using a newer websocket release? |
See #1927. It looks like an issue in the current implementation. If you're replacing it with a new implementation, you can safely bump the dependency. |
@aaugustin I implemented it on version 10.4. (#2060) where ServerConnection was providing sans-I/O. Changing the version to 11.0 would require to change it to ServerProtocol. and I guess, the apis of both the classes is same. or should some changes also be required there. |
It's just a renaming. There's another minor change:
but it doesn't affect you because you're already using keyword arguments in your PR. |
@Kludex As websockets version was changed to 11.0.3 on master. So changed the pr accordingly |
@Kludex Looks like |
Hello, I didn't track the latest status of this effort — as a reminder:
|
Given python-websockets/websockets#975 and python-websockets/websockets#1310 (comment) we should try to follow @aaugustin's recommendation.
We can discuss if we should deprecate the current
WebSocketProtocol
, or if we should replace it, and that's it.Important
The text was updated successfully, but these errors were encountered: