wrap background cleanup in finally, add tests

This commit is contained in:
Timothy Pogue
2022-09-10 11:47:21 -06:00
parent 4250174de9
commit d8cdd92140
2 changed files with 42 additions and 3 deletions

View File

@@ -200,14 +200,17 @@ class ApiServer(RPCHandler):
# Sleep, make this configurable?
await asyncio.sleep(0.1)
except asyncio.CancelledError:
# Disconnect channels and stop the loop on cancel
await self._ws_channel_manager.disconnect_all()
self._ws_loop.stop()
pass
# For testing, shouldn't happen when stable
except Exception as e:
logger.exception(f"Exception happened in background task: {e}")
finally:
# Disconnect channels and stop the loop on cancel
await self._ws_channel_manager.disconnect_all()
self._ws_loop.stop()
def start_api(self):
"""
Start API ... should be run in thread.