mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2025-09-05 01:00:23 +02:00
Session.close: Call close handler on websocket close
When scratch closes websocket connection, bluepy-scratch-link does not close Bluetooth connection cleanly. This causes connection failure on reconnect. To close Bluetooth connection, catch ConnectionClosedError of websocket and call close handler of the session. Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
This commit is contained in:
@@ -120,10 +120,22 @@ class Session():
|
||||
await self.recv_request()
|
||||
await asyncio.sleep(0.1)
|
||||
while True:
|
||||
if await self.recv_request():
|
||||
try:
|
||||
if await self.recv_request():
|
||||
break
|
||||
await self._send_notifications()
|
||||
logger.debug("in handle loop")
|
||||
except websockets.ConnectionClosedError as e:
|
||||
logger.info("scratch closed session")
|
||||
logger.debug(e)
|
||||
self.close()
|
||||
break
|
||||
await self._send_notifications()
|
||||
logger.debug("in handle loop")
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Default handler called at session end.
|
||||
"""
|
||||
return
|
||||
|
||||
class BTSession(Session):
|
||||
"""Manage a session for Bluetooth device"""
|
||||
|
Reference in New Issue
Block a user