mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2025-09-07 10:10:24 +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 self.recv_request()
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
if await self.recv_request():
|
if await self.recv_request():
|
||||||
break
|
break
|
||||||
await self._send_notifications()
|
await self._send_notifications()
|
||||||
logger.debug("in handle loop")
|
logger.debug("in handle loop")
|
||||||
|
except websockets.ConnectionClosedError as e:
|
||||||
|
logger.info("scratch closed session")
|
||||||
|
logger.debug(e)
|
||||||
|
self.close()
|
||||||
|
break
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
"""
|
||||||
|
Default handler called at session end.
|
||||||
|
"""
|
||||||
|
return
|
||||||
|
|
||||||
class BTSession(Session):
|
class BTSession(Session):
|
||||||
"""Manage a session for Bluetooth device"""
|
"""Manage a session for Bluetooth device"""
|
||||||
|
Reference in New Issue
Block a user