Compruebe si Rhythmbox se está ejecutando a través de Python

I am trying to extract information from Rhythmbox via dbus, but I only want to do so, if Rhythmbox is running. Is there a way to check if Rhythmbox is running via Python without starting it if it is not running?

Whenever I invoke the dbus código como este:

bus = dbus.Bus()
obj = bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
iface = dbus.Interface(obj, "org.gnome.Rhythmbox.Shell)

and Rhythmbox is not running, it then starts it.

Can I check via dbus if Rhythmbox is running without actually starting it? Or is there any other way, other than parsing the list of currently running processes, to do so?

preguntado el 08 de enero de 11 a las 18:01

2 Respuestas

This is similar to Rosh Oxymoron's answer, but arguably neater (albeit untested):

bus = dbus.SessionBus()
if bus.name_has_owner('org.gnome.Rhythmbox'):
    # ...

If you want to be notified when Rhythmbox starts or stops, you can use:

def rhythmbox_owner_changed(new_owner):
    if new_owner == '':
        print 'Rhythmbox is no longer running'
    else:
        print 'Rhythmbox is now running'

bus.watch_name_owner('org.gnome.Rhythmbox')

Consulta las documentation for dbus.bus.BusConnection para más información.

Respondido el 14 de enero de 11 a las 00:01

dbus_main_object = bus.get_object("org.freedesktop.DBus", "/")
dbus_names = dbus_main_object.ListNames(dbus_interface='org.freedesktop.DBus')
if 'org.gnome.Rhythmbox' in dbus_names:
    do_whatever()

Respondido el 08 de enero de 11 a las 23:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.