diff --git a/src/idom/backend/flask.py b/src/idom/backend/flask.py index ac9c83ea3..4b2f3244d 100644 --- a/src/idom/backend/flask.py +++ b/src/idom/backend/flask.py @@ -80,7 +80,7 @@ async def serve_development_app( started: asyncio.Event | None = None, ) -> None: """Run an application using a development server""" - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() stopped = asyncio.Event() server: Ref[BaseWSGIServer] = Ref() diff --git a/src/idom/backend/tornado.py b/src/idom/backend/tornado.py index 2e45cab0c..a409c5daf 100644 --- a/src/idom/backend/tornado.py +++ b/src/idom/backend/tornado.py @@ -75,7 +75,7 @@ async def serve_development_app( try: # block forever - tornado has already set up its own background tasks - await asyncio.get_event_loop().create_future() + await asyncio.get_running_loop().create_future() finally: # stop accepting new connections server.stop() diff --git a/src/idom/backend/utils.py b/src/idom/backend/utils.py index 063bc01af..a3c5ee51a 100644 --- a/src/idom/backend/utils.py +++ b/src/idom/backend/utils.py @@ -53,9 +53,7 @@ def run( f"Running with {app_cls.__module__}.{app_cls.__name__} at http://{host}:{port}" ) - asyncio.get_event_loop().run_until_complete( - implementation.serve_development_app(app, host, port) - ) + asyncio.run(implementation.serve_development_app(app, host, port)) def safe_client_build_dir_path(path: str) -> Path: diff --git a/src/idom/core/layout.py b/src/idom/core/layout.py index 5f7d667ad..38bdd6490 100644 --- a/src/idom/core/layout.py +++ b/src/idom/core/layout.py @@ -716,7 +716,7 @@ class _ThreadSafeQueue(Generic[_Type]): __slots__ = "_loop", "_queue", "_pending" def __init__(self) -> None: - self._loop = asyncio.get_event_loop() + self._loop = asyncio.get_running_loop() self._queue: asyncio.Queue[_Type] = asyncio.Queue() self._pending: Set[_Type] = set() diff --git a/tests/test_backend/test_utils.py b/tests/test_backend/test_utils.py index 4820b6031..032bdac9c 100644 --- a/tests/test_backend/test_utils.py +++ b/tests/test_backend/test_utils.py @@ -34,16 +34,15 @@ async def test_run(page: Page, exit_stack: ExitStack): port = find_available_port(host) url = f"http://{host}:{port}" - def run_in_thread(): - asyncio.set_event_loop(loop) - sync_run( + threading.Thread( + target=lambda: sync_run( SampleApp, host, port, implementation=flask_implementation, - ) - - threading.Thread(target=run_in_thread, daemon=True).start() + ), + daemon=True, + ).start() # give the server a moment to start time.sleep(0.5)