From bba625c21555622b18c182284721426aa9dff557 Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 23 Nov 2024 19:12:00 +0100 Subject: [PATCH] Removes the thread handling in MatrixPush class --- matrix_display.py | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/matrix_display.py b/matrix_display.py index f38365e..d3cd845 100644 --- a/matrix_display.py +++ b/matrix_display.py @@ -884,22 +884,15 @@ def __init__(self, host: str) -> None: ## App-available methods - # Thread-safe clear async def clear(self) -> bool: # Is task running? if self._task_loop != None: - # Ask for execution in the task thread - concurrent_future = asyncio.run_coroutine_threadsafe(self._internal_clear(), self._task_loop) - # Wait in the calling thread - return await asyncio.wrap_future(concurrent_future) + # Do the internal clear + # Set clear flag + self._clear_flag = True + await self._not_uploading.wait() - # Else send a detached clear in the calling thread - return await self._send_clear() - - ## ## - - ## Independent send a clear command to the display - async def _send_clear(self) -> bool: + # Send a clear command to the display anyway async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=30)) as http_cli: try: async with http_cli.get(basic_url(self._s_host, "/clear"), compress=False) as http_res: @@ -917,19 +910,11 @@ async def _send_clear(self) -> bool: except aiohttp.ClientError as e: LOGGER.error("Display: Unable to clear matrix! {exc!s}", exc=e) - return False - - ## Task - # Concurrent task-thread clear management - async def _internal_clear(self) -> bool: - # Set clear flag - self._clear_flag = True + return False - # Send clear to the display - await self._not_uploading.wait() - return await self._send_clear() + ## ## - # Task + ## Task async def run(self) -> NoReturn: try: self._task_loop = asyncio.get_running_loop()