Skip to content

Commit

Permalink
fix asyncio deprectation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Oct 29, 2022
1 parent a021193 commit efe272b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/idom/backend/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/idom/backend/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions src/idom/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/idom/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
11 changes: 5 additions & 6 deletions tests/test_backend/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit efe272b

Please sign in to comment.