Code review actions

This commit is contained in:
Darren Burns
2022-04-11 17:01:20 +01:00
parent 63be3ab4f0
commit 36d7973c7c
3 changed files with 10 additions and 8 deletions

View File

@@ -14,7 +14,6 @@ from aiohttp import ClientResponseError, ClientConnectorError, ClientWebSocketRe
from rich.console import Console
from rich.segment import Segment
DEFAULT_PORT = 8081
WEBSOCKET_CONNECT_TIMEOUT = 3
LOG_QUEUE_MAXSIZE = 512
@@ -40,14 +39,10 @@ class DevtoolsConsole(Console):
class DevtoolsConnectionError(Exception):
"""Raise when the devtools client is unable to connect to the server"""
pass
class ClientShutdown:
"""Sentinel type sent to client queue(s) to indicate shutdown"""
pass
class DevtoolsClient:
"""Client responsible for websocket communication with the devtools server.

View File

@@ -5,6 +5,9 @@ from datetime import datetime, timezone
from pathlib import Path
from typing import Iterable
from rich.style import Style
from rich.text import Text
if sys.version_info >= (3, 8):
from typing import Literal
else:
@@ -59,7 +62,9 @@ class DevtoolsLogMessage:
file_and_line = escape(f"{Path(self.path).name}:{self.line_number}")
table.add_row(
f" [#888177]{local_time.time()} [dim]{timezone_name}[/]",
Align.right(f"[#888177][link={file_link}]{file_and_line} "),
Align.right(
Text(f"{file_and_line} ", style=Style(color="#888177", link=file_link))
),
style="on #292724",
)
yield table

View File

@@ -92,11 +92,13 @@ class DevtoolsService:
"""Handles a single client connection"""
client = ClientHandler(request, service=self)
self.clients.append(client)
websocket = await client.start()
websocket = await client.run()
self.clients.remove(client)
return websocket
async def shutdown(self) -> None:
"""Stop server async tasks and clean up all client handlers"""
# Stop polling/writing Console dimensions to clients
self.shutdown_event.set()
await self.size_poll_task
@@ -180,7 +182,7 @@ class ClientHandler:
self.service.console.print(info_renderable)
self.incoming_queue.task_done()
async def start(self) -> WebSocketResponse:
async def run(self) -> WebSocketResponse:
"""Prepare the websocket and communication queues, and continuously
read messages from the queues.