Skip to content
Snippets Groups Projects
Commit 8e53b89a authored by Michał Kudela's avatar Michał Kudela
Browse files

Replace sleep with asyncio.sleep for async compatibility

parent ef6b8c6f
No related tags found
No related merge requests found
Pipeline #119311 failed
...@@ -3,7 +3,6 @@ from __future__ import annotations ...@@ -3,7 +3,6 @@ from __future__ import annotations
import asyncio import asyncio
from collections import defaultdict from collections import defaultdict
from threading import Thread from threading import Thread
from time import sleep
from typing import TYPE_CHECKING, Any, Final from typing import TYPE_CHECKING, Any, Final
from beekeepy._communication.abc.notification_handler import NotificationHandler from beekeepy._communication.abc.notification_handler import NotificationHandler
...@@ -63,9 +62,12 @@ class UniversalNotificationServer(ContextSync[int]): ...@@ -63,9 +62,12 @@ class UniversalNotificationServer(ContextSync[int]):
time_to_launch_notification_server: Final[float] = 0.5 time_to_launch_notification_server: Final[float] = 0.5
assert self.__server_thread is None, "Server thread is not None; Is server still running?" 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() 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 return self.__http_server.port
def close(self) -> None: def close(self) -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment