Skip to content

Instantly share code, notes, and snippets.

Created January 5, 2016 11:10
Show Gist options
  • Save txus/8fd7842dbb3ea11ab102 to your computer and use it in GitHub Desktop.
Save txus/8fd7842dbb3ea11ab102 to your computer and use it in GitHub Desktop.
Python is crazy


You'll need dbus running. In a console:


In another console:


Exposing the bug

In line 32, replace:

bus_name = dbus.service.BusName('org.example.Ui', bus)


dbus.service.BusName('org.example.Ui', bus)


I'm guessing BusName initializes an object that in its construction has the side effect of publishing a service on dbus, and if it's not assigned to anything, the python interpreter discards it, and thus destroys it, which probably causes the dbus service to disappear. Bonkers.

#!/usr/bin/env python
import dbus
bus = dbus.SessionBus()
service_name = 'org.example.Ui'
ui = bus.get_object(service_name, '/')
iface = dbus.Interface(ui, dbus_interface=service_name)
#!/usr/bin/env python
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
import logging
logger = logging.getLogger(__name__)
class Ui(dbus.service.Object):
def __init__(self, bus, path):
# Set up any needed state (hopefully none)
dbus.service.Object.__init__(self, bus, path)
in_signature='', out_signature='')
def LaunchBrowser(self):"launchin' the browser")
if __name__ == '__main__':
loop = gobject.MainLoop()
bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.example.Ui', bus)
Ui(bus, '/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment