From 83b00cdabbd07ee416278e6322cf9117c89083e4 Mon Sep 17 00:00:00 2001 From: kavan Date: Thu, 25 Jul 2019 00:13:16 +0530 Subject: [PATCH] Add timeout support on `introspect` with asyncio.wait_for --- dbus_next/aio/message_bus.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dbus_next/aio/message_bus.py b/dbus_next/aio/message_bus.py index decef81..a98a5b5 100644 --- a/dbus_next/aio/message_bus.py +++ b/dbus_next/aio/message_bus.py @@ -114,7 +114,7 @@ def on_match_added(reply, err): return await future - async def introspect(self, bus_name: str, path: str) -> intr.Node: + async def introspect(self, bus_name: str, path: str, timeout: float = 30.0) -> intr.Node: """Get introspection data for the node at the given path from the given bus name. @@ -125,6 +125,8 @@ async def introspect(self, bus_name: str, path: str) -> intr.Node: :type bus_name: str :param path: The path to introspect. :type path: str + :param timeout: The timeout to introspect. + :type timeout: float :returns: The introspection data for the name at the path. :rtype: :class:`Node ` @@ -137,6 +139,7 @@ async def introspect(self, bus_name: str, path: str) -> intr.Node: - :class:`DBusError ` - If the service threw \ an error for the method call or returned an invalid result. - :class:`Exception` - If a connection error occurred. + - :class:`asyncio.TimeoutError` - Waited for future but time run out. """ future = self._loop.create_future() @@ -148,7 +151,7 @@ def reply_handler(reply, err): super().introspect(bus_name, path, reply_handler) - return await future + return await asyncio.wait_for(future, timeout=timeout) async def request_name(self, name: str, flags: NameFlag = NameFlag.NONE) -> RequestNameReply: """Request that this message bus owns the given name.