From 8e53b89ae29bc55f939a33c7889a7dde08ac4fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kudela?= <kudmich@syncad.com> Date: Tue, 1 Apr 2025 11:58:35 +0000 Subject: [PATCH] Replace sleep with asyncio.sleep for async compatibility --- .../_communication/universal_notification_server.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/beekeepy/beekeepy/_communication/universal_notification_server.py b/beekeepy/beekeepy/_communication/universal_notification_server.py index 7813e49b..1873659a 100644 --- a/beekeepy/beekeepy/_communication/universal_notification_server.py +++ b/beekeepy/beekeepy/_communication/universal_notification_server.py @@ -3,7 +3,6 @@ from __future__ import annotations import asyncio from collections import defaultdict from threading import Thread -from time import sleep from typing import TYPE_CHECKING, Any, Final from beekeepy._communication.abc.notification_handler import NotificationHandler @@ -63,9 +62,12 @@ class UniversalNotificationServer(ContextSync[int]): time_to_launch_notification_server: Final[float] = 0.5 assert self.__server_thread is None, "Server thread is not None; Is server still running?" - self.__server_thread = Thread(target=asyncio.run, args=(self.__http_server.run(),), name=self.__thread_name) + self.__loop = asyncio.new_event_loop() + self.__server_thread = Thread(target=self.__http_server.run, args=(self.__loop,), name=self.__thread_name) self.__server_thread.start() - sleep(time_to_launch_notification_server) + + future = asyncio.run_coroutine_threadsafe(asyncio.sleep(time_to_launch_notification_server), self.__loop) + future.result() return self.__http_server.port def close(self) -> None: -- GitLab