Skip to content

Commit 7f8bb45

Browse files
committed
Fix examples for high level service interface
If we first `request_name` and then `bus.export` our service then there is a (short) period of time when we already own the name but our MessageBus class doesn't know which services shall it provide. As a result, if we get a request in this period of time, we will reply with an error "SERVICE.METHOD with signature SIGNATURE not found". This situation will happen regularly if we are started by dbus-daemon because we were declared in the `.service` file. For example: ``` [D-BUS Service] Name=test.name Exec=/path/to/my/service.py ``` With the old vesion of examples, this will fail to handle the first request for which D-Bus started our service.
1 parent a55c363 commit 7f8bb45

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ class ExampleInterface(ServiceInterface):
117117

118118
async def main():
119119
bus = await MessageBus().connect()
120-
await bus.request_name('test.name')
121120
interface = ExampleInterface('test.interface')
122121
bus.export('/test/path', interface)
122+
# now that we are ready to handle requests, we can request name from D-Bus
123+
await bus.request_name('test.name')
124+
# wait indefinitely
123125
await asyncio.get_event_loop().create_future()
124126

125127
asyncio.get_event_loop().run_until_complete(main())

docs/high-level-service/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ After the service interface is defined, call :func:`MessageBus.export() <dbus_ne
7777
7878
async def main():
7979
bus = await MessageBus().connect()
80-
await bus.request_name('com.example.name')
8180
interface = ExampleInterface()
8281
bus.export('/com/example/sample0', interface)
82+
await bus.request_name('com.example.name')
8383
8484
# emit the changed signal after two seconds.
8585
await asyncio.sleep(2)

examples/example-service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ async def main():
5454
interface_name = 'example.interface'
5555

5656
bus = await MessageBus().connect()
57-
await bus.request_name(name)
5857
interface = ExampleInterface(interface_name)
5958
bus.export('/example/path', interface)
59+
await bus.request_name(name)
6060
print(f'service up on name: "{name}", path: "{path}", interface: "{interface_name}"')
6161
await asyncio.get_event_loop().create_future()
6262

0 commit comments

Comments
 (0)