Skip to content

Commit c861b50

Browse files
author
Tony Crisci
authored
Merge pull request #39 from MarSoft/fix-service-example
Fix race condition in examples for high level service interface
2 parents a55c363 + 7f8bb45 commit c861b50

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

README.md

+3-1
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

+1-1
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

+1-1
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)