Skip to content

Commit d53ad83

Browse files
committed
fix asyncio deprectation warning
1 parent a021193 commit d53ad83

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

src/idom/backend/default.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from typing import Any
4+
from typing import Any, NoReturn
55

66
from idom.types import RootComponentConstructor
77

@@ -23,9 +23,9 @@ def create_development_app() -> Any:
2323
return _default_implementation().create_development_app()
2424

2525

26-
def Options(*args: Any, **kwargs: Any) -> Any:
26+
def Options(*args: Any, **kwargs: Any) -> NoReturn:
2727
"""Create configuration options"""
28-
return _default_implementation().Options(*args, **kwargs)
28+
raise ValueError("Default implementation has no options.") # pragma: no cover
2929

3030

3131
async def serve_development_app(

src/idom/backend/flask.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def serve_development_app(
8080
started: asyncio.Event | None = None,
8181
) -> None:
8282
"""Run an application using a development server"""
83-
loop = asyncio.get_event_loop()
83+
loop = asyncio.get_running_loop()
8484
stopped = asyncio.Event()
8585

8686
server: Ref[BaseWSGIServer] = Ref()

src/idom/backend/tornado.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def serve_development_app(
7575

7676
try:
7777
# block forever - tornado has already set up its own background tasks
78-
await asyncio.get_event_loop().create_future()
78+
await asyncio.get_running_loop().create_future()
7979
finally:
8080
# stop accepting new connections
8181
server.stop()

src/idom/backend/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def run(
5353
f"Running with {app_cls.__module__}.{app_cls.__name__} at http://{host}:{port}"
5454
)
5555

56-
asyncio.get_event_loop().run_until_complete(
57-
implementation.serve_development_app(app, host, port)
58-
)
56+
asyncio.run(implementation.serve_development_app(app, host, port))
5957

6058

6159
def safe_client_build_dir_path(path: str) -> Path:

src/idom/core/layout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ class _ThreadSafeQueue(Generic[_Type]):
716716
__slots__ = "_loop", "_queue", "_pending"
717717

718718
def __init__(self) -> None:
719-
self._loop = asyncio.get_event_loop()
719+
self._loop = asyncio.get_running_loop()
720720
self._queue: asyncio.Queue[_Type] = asyncio.Queue()
721721
self._pending: Set[_Type] = set()
722722

tests/test_backend/test_utils.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ async def test_run(page: Page, exit_stack: ExitStack):
3434
port = find_available_port(host)
3535
url = f"http://{host}:{port}"
3636

37-
def run_in_thread():
38-
asyncio.set_event_loop(loop)
39-
sync_run(
37+
threading.Thread(
38+
target=lambda: sync_run(
4039
SampleApp,
4140
host,
4241
port,
4342
implementation=flask_implementation,
44-
)
45-
46-
threading.Thread(target=run_in_thread, daemon=True).start()
43+
),
44+
daemon=True,
45+
).start()
4746

4847
# give the server a moment to start
4948
time.sleep(0.5)

0 commit comments

Comments
 (0)