-
-
Notifications
You must be signed in to change notification settings - Fork 540
Websocket closes its connection on access from async method #122
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
Comments
Your "serve" coroutine exits immediately after sending "welcome". At that point the websocket is closed. You need See the documentation for details. |
I don't agree. Why would I do a loop in the server coroutine when it serves already its purpose? On a new websocket connection I add the websocket to the Queue which works if you see error.log. There is no need for a while loop... The error seems more related to the Queue not being able to stock the websocket instances. |
You're welcome to disagree with the API of the library but I can't help you in that case. websockets is designed and documented to close the websocket connection when the "handler" coroutine exits. This is what happens, whether you agree or not, and changing it would be very backwards-incompatible. |
Wouldn't keeping alive a handler by |
The resource consumption is so low I cannot measure it. I tried running 100000 sleeps in parallel:
Starting them consumes some CPU; then once they're all sleeping I tried again with 1000000 but I couldn't start the coroutines:
With the current design, each websocket connection requires two alive coroutines. If one of them is just blocked Managing 100k connections in a single Python process would be a good result and my proposal has 0,0% overhead in that case. I don't know if it consumes something or nothing at all because I don't know how to get a better resolution. Usually you have to bypass the OS' TCP stack long before you reach that scale... |
Thank you for your input. It is solved with binarytrails/smoll@3b9e9d3. |
https://github.com/sevaivanov/small-projects/tree/master/python/websockets/thread-asyncio
The text was updated successfully, but these errors were encountered: