aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-06-04 20:23:22 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-06-04 20:23:22 -0400
commit2a01b1cba8af5891bac632683286951e2c3f95f0 (patch)
treec108ff3f57972fa4b6fc19388879917029ba4284
parent9f9560dd1f0f01d50c3c31b7fb2f083e1dc80a0e (diff)
downloadqmenumodel-2a01b1cba8af5891bac632683286951e2c3f95f0.tar.gz
qmenumodel-2a01b1cba8af5891bac632683286951e2c3f95f0.tar.bz2
qmenumodel-2a01b1cba8af5891bac632683286951e2c3f95f0.zip
examples/exportmenu.py: use g_bus_own_name to avoid race
This avoids the common d-bus race where a name is owned but objects aren't exported on it yet.
-rwxr-xr-xexamples/exportmenu.py20
1 files changed, 3 insertions, 17 deletions
diff --git a/examples/exportmenu.py b/examples/exportmenu.py
index 767d8b9..b7c37b1 100755
--- a/examples/exportmenu.py
+++ b/examples/exportmenu.py
@@ -32,22 +32,7 @@ from gi.repository import GLib
BUS_NAME = 'com.canonical.testmenu'
BUS_OBJECT_PATH = '/com/canonical/testmenu'
-
-if __name__ == '__main__':
- bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
- # Claim well-known bus name and ensure only one instance of self is running
- # at any given time.
- # http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-names
- proxy = Gio.DBusProxy.new_sync(bus, 0, None,
- 'org.freedesktop.DBus',
- '/org/freedesktop/DBus',
- 'org.freedesktop.DBus', None)
- result = proxy.RequestName('(su)', BUS_NAME, 0x4)
- if result != 1 :
- print >> sys.stderr, ("Name '%s' is already owned on the session bus."
- "Aborting.") % BUS_NAME
- sys.exit(1)
-
+def bus_acquired(bus, name):
menu = Gio.Menu()
foo = Gio.MenuItem.new('foo', 'app.foo')
foo.set_attribute_value('x-additionaltext',
@@ -78,5 +63,6 @@ if __name__ == '__main__':
actions.add_action(Gio.SimpleAction.new("bar", None))
bus.export_action_group(BUS_OBJECT_PATH, actions)
+if __name__ == '__main__':
+ Gio.bus_own_name(Gio.BusType.SESSION, BUS_NAME, 0, bus_acquired, None, None)
GLib.MainLoop().run()
-