From 691ff8e1bf6121b7f8c8428bb805be1d27f0a06f Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 26 Sep 2022 12:43:56 -0500 Subject: [PATCH] replace deprecated asyncio.get_event_loop() `asyncio.get_event_loop()` was deprecated in Python 3.10, so we should use `asyncio.get_running_loop()` instead. --- README.md | 8 ++++---- docs/source/high-level-service/index.rst | 2 +- examples/aio-list-names.py | 2 +- examples/aio-tcp-notification.py | 2 +- examples/dbus-next-send.py | 2 +- examples/example-service.py | 2 +- examples/mpris.py | 2 +- src/dbus_fast/aio/message_bus.py | 2 +- tests/service/test_properties.py | 2 +- tests/service/test_signals.py | 4 ++-- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 52ae87a..987baaa 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ from dbus_fast.aio import MessageBus import asyncio -loop = asyncio.get_event_loop() +loop = asyncio.get_running_loop() async def main(): @@ -159,9 +159,9 @@ async def main(): # now that we are ready to handle requests, we can request name from D-Bus await bus.request_name('test.name') # wait indefinitely - await asyncio.get_event_loop().create_future() + await asyncio.get_running_loop().create_future() -asyncio.get_event_loop().run_until_complete(main()) +asyncio.get_running_loop().run_until_complete(main()) ``` ## The Low-Level Interface @@ -177,7 +177,7 @@ from dbus_fast.aio import MessageBus import asyncio import json -loop = asyncio.get_event_loop() +loop = asyncio.get_running_loop() async def main(): diff --git a/docs/source/high-level-service/index.rst b/docs/source/high-level-service/index.rst index 4adf1aa..e8f86f4 100644 --- a/docs/source/high-level-service/index.rst +++ b/docs/source/high-level-service/index.rst @@ -90,4 +90,4 @@ If any file descriptors are sent or received (DBus type ``h``), the variable ref await bus.wait_for_disconnect() - asyncio.get_event_loop().run_until_complete(main()) + asyncio.get_running_loop().run_until_complete(main()) diff --git a/examples/aio-list-names.py b/examples/aio-list-names.py index cfb1bb2..41f9af4 100755 --- a/examples/aio-list-names.py +++ b/examples/aio-list-names.py @@ -10,7 +10,7 @@ import json from dbus_fast import Message, MessageType from dbus_fast.aio import MessageBus -loop = asyncio.get_event_loop() +loop = asyncio.get_running_loop() async def main(): diff --git a/examples/aio-tcp-notification.py b/examples/aio-tcp-notification.py index b9d69db..2687229 100755 --- a/examples/aio-tcp-notification.py +++ b/examples/aio-tcp-notification.py @@ -17,7 +17,7 @@ import asyncio from dbus_fast.aio import MessageBus -loop = asyncio.get_event_loop() +loop = asyncio.get_running_loop() async def main(): diff --git a/examples/dbus-next-send.py b/examples/dbus-next-send.py index f4bb7ea..1fe48b5 100755 --- a/examples/dbus-next-send.py +++ b/examples/dbus-next-send.py @@ -101,7 +101,7 @@ else: if not signature: exit_error("--signature is a required argument when passing a message body") -loop = asyncio.get_event_loop() +loop = asyncio.get_running_loop() async def main(): diff --git a/examples/example-service.py b/examples/example-service.py index 8ceb9a9..a34ac6a 100755 --- a/examples/example-service.py +++ b/examples/example-service.py @@ -64,4 +64,4 @@ async def main(): await bus.wait_for_disconnect() -asyncio.get_event_loop().run_until_complete(main()) +asyncio.get_running_loop().run_until_complete(main()) diff --git a/examples/mpris.py b/examples/mpris.py index 79cd85d..3b26b68 100755 --- a/examples/mpris.py +++ b/examples/mpris.py @@ -8,7 +8,7 @@ import asyncio from dbus_fast.aio import MessageBus -loop = asyncio.get_event_loop() +loop = asyncio.get_running_loop() async def main(): diff --git a/src/dbus_fast/aio/message_bus.py b/src/dbus_fast/aio/message_bus.py index 637ee3f..468640c 100644 --- a/src/dbus_fast/aio/message_bus.py +++ b/src/dbus_fast/aio/message_bus.py @@ -161,7 +161,7 @@ class MessageBus(BaseMessageBus): ): super().__init__(bus_address, bus_type, ProxyObject) self._negotiate_unix_fd = negotiate_unix_fd - self._loop = asyncio.get_event_loop() + self._loop = asyncio.get_running_loop() self._unmarshaller = self._create_unmarshaller() self._writer = _MessageWriter(self) diff --git a/tests/service/test_properties.py b/tests/service/test_properties.py index 2b57743..ebf85a9 100644 --- a/tests/service/test_properties.py +++ b/tests/service/test_properties.py @@ -270,7 +270,7 @@ async def test_property_changed_signal(interface_class): async def wait_for_message(): # TODO timeout - future = asyncio.get_event_loop().create_future() + future = asyncio.get_running_loop().create_future() def message_handler(signal): if signal.interface == "org.freedesktop.DBus.Properties": diff --git a/tests/service/test_signals.py b/tests/service/test_signals.py index 5534ea3..35d0af9 100644 --- a/tests/service/test_signals.py +++ b/tests/service/test_signals.py @@ -60,7 +60,7 @@ class SecondExampleInterface(ServiceInterface): class ExpectMessage: def __init__(self, bus1, bus2, interface_name, timeout=1): - self.future = asyncio.get_event_loop().create_future() + self.future = asyncio.get_running_loop().create_future() self.bus1 = bus1 self.bus2 = bus2 self.interface_name = interface_name @@ -78,7 +78,7 @@ class ExpectMessage: async def __aenter__(self): self.bus2.add_message_handler(self.message_handler) - self.timeout_task = asyncio.get_event_loop().call_later( + self.timeout_task = asyncio.get_running_loop().call_later( self.timeout, self.timeout_cb )