From 942e5e485521f75518ca1a090effca2213d5582a Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Tue, 21 Jan 2025 13:45:44 +0100 Subject: [PATCH] Revert "Fix leaked semaphore object warning (#4132)" This reverts commit c202f3eddfcc60a602fa21e8d5eebb37ab239886. --- nicegui/native/__init__.py | 4 +--- nicegui/native/native.py | 30 +++--------------------------- nicegui/native/native_mode.py | 2 -- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/nicegui/native/__init__.py b/nicegui/native/__init__.py index cabde5d04..2fb64809b 100644 --- a/nicegui/native/__init__.py +++ b/nicegui/native/__init__.py @@ -1,4 +1,4 @@ -from .native import WindowProxy, create_queues, method_queue, remove_queues, response_queue +from .native import WindowProxy, method_queue, response_queue from .native_config import NativeConfig from .native_mode import activate, find_open_port @@ -6,9 +6,7 @@ 'NativeConfig', 'WindowProxy', 'activate', - 'create_queues', 'find_open_port', 'method_queue', - 'remove_queues', 'response_queue', ] diff --git a/nicegui/native/native.py b/nicegui/native/native.py index db777506b..f432f8e81 100644 --- a/nicegui/native/native.py +++ b/nicegui/native/native.py @@ -2,34 +2,13 @@ import inspect import warnings from multiprocessing import Queue -from typing import Any, Callable, Optional, Tuple +from typing import Any, Callable, Tuple from .. import run from ..logging import log -method_queue: Optional[Queue] = None -response_queue: Optional[Queue] = None - - -def create_queues() -> None: - """Create the message queues.""" - global method_queue, response_queue # pylint: disable=global-statement # noqa: PLW0603 - method_queue = Queue() - response_queue = Queue() - - -def remove_queues() -> None: - """Remove the message queues by closing them and waiting for threads to finish.""" - global method_queue, response_queue # pylint: disable=global-statement # noqa: PLW0603 - if method_queue is not None: - method_queue.close() - method_queue.join_thread() - method_queue = None - if response_queue is not None: - response_queue.close() - response_queue.join_thread() - response_queue = None - +method_queue: Queue = Queue() +response_queue: Queue = Queue() try: with warnings.catch_warnings(): @@ -141,14 +120,11 @@ def expose(self, function: Callable) -> None: # type: ignore # pylint: disable= def _send(self, *args: Any, **kwargs: Any) -> None: name = inspect.currentframe().f_back.f_code.co_name # type: ignore - assert method_queue is not None method_queue.put((name, args, kwargs)) async def _request(self, *args: Any, **kwargs: Any) -> Any: def wrapper(*args: Any, **kwargs: Any) -> Any: try: - assert method_queue is not None - assert response_queue is not None method_queue.put((name, args, kwargs)) return response_queue.get() # wait for the method to be called and writing its result to the queue except Exception: diff --git a/nicegui/native/native_mode.py b/nicegui/native/native_mode.py index d0de71b90..fde7fc36a 100644 --- a/nicegui/native/native_mode.py +++ b/nicegui/native/native_mode.py @@ -104,7 +104,6 @@ def check_shutdown() -> None: while not core.app.is_stopped: time.sleep(0.1) _thread.interrupt_main() - native.remove_queues() if not optional_features.has('webview'): log.error('Native mode is not supported in this configuration.\n' @@ -112,7 +111,6 @@ def check_shutdown() -> None: sys.exit(1) mp.freeze_support() - native.create_queues() args = host, port, title, width, height, fullscreen, frameless, native.method_queue, native.response_queue process = mp.Process(target=_open_window, args=args, daemon=True) process.start()