#`EBADF` I believe is the underlying
1 messages · Page 1 of 1 (latest)
I got it to crash on PiPico
Traceback (most recent call last):
File "<stdin>", line 72, in handle_websocket_requests
File "adafruit_httpserver/response.py", line 766, in receive
File "adafruit_httpserver/response.py", line 754, in receive
File "adafruit_httpserver/response.py", line 687, in _read_frame
OSError: [Errno 9] EBADFDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 143, in <module>
File "asyncio/core.py", line 317, in run
File "asyncio/core.py", line 276, in run_until_complete
File "asyncio/core.py", line 261, in run_until_complete
File "<stdin>", line 140, in main
File "asyncio/funcs.py", line 162, in gather
File "asyncio/core.py", line 261, in run_until_complete
File "<stdin>", line 77, in handle_websocket_requests
File "adafruit_httpserver/response.py", line 838, in close
File "adafruit_httpserver/response.py", line 822, in send_message
File "adafruit_httpserver/response.py", line 142, in _send_bytes
OSError: [Errno 9] EBADF
Is there anyway to detect the closure of the websocket and not call websocket.recieve? Here is the code:
`async def handle_websocket_requests():
global dict_data
global websocket
while True:
try:
if websocket is not None:
data = websocket.receive(fail_silently=False)
if data is not None:
dict_data=json.loads(data)
print(data)
except Exception as e:
websocket.close() # Close any existing connection
websocket=None
print("Error-handle_websocket_requests:", str(e))
await asyncio.sleep(0.001)`
I switched from WebSockets to REST PUT, and it is now stable. There is something not correct with the WebSocket code that makes it unstable. Originally, I thought WebSocket would perform better. Since I only send the current direction and only on change, the REST API is working well. One advantage of REST is that it does not require any connection management to ensure the connection is still open and active.