python-trio / trio-websocket

WebSocket client and server implementation for Python Trio
MIT License
70 stars 26 forks source link

example client: cancel command loop on close of connection #52

Closed belm0 closed 6 years ago

belm0 commented 6 years ago

Intended to fix #22.

It does handle the connection close cases fine. However it somehow breaks normal communication. Before this change, here is server-side log from "send foo":

DEBUG:trio-websocket:conn#1 received 9 bytes
DEBUG:trio-websocket:conn#1 received event: TextReceived
DEBUG:trio-websocket:conn#1 sending 5 bytes

With this change, the server gets the bytes but appears to not recognize the end of the message, so never reponds:

DEBUG:trio-websocket:conn#2 received 9 bytes
njsmith commented 6 years ago

It looks like you're starting handle_connection in the background, and then immediately closing the connection and cancelling it?

belm0 commented 6 years ago

Yes, thank you-- this confusion resulted from observed behavior of open_websocket_url context manager hanging when I was using an older wsproto.