dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown

Issue #3 new
Former user created an issue

Hello,

when using notify2 repeatedly after some time delay (notifications every other minute or so), I have a systematic crash :

    note.show()
  File "/usr/lib/python3/dist-packages/notify2.py", line 188, in show
    self.timeout,  # expire_timeout
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name :1.34 was not provided by any .service files

As far as I understood dbus and your documentation, it should work independently of appname=qt/gtk and environment ...

The crash does not happen, when I send for example 10 notifications in a row, like each one after < 0.1 sec or less.

I don't know exactly what happens, but it works (with the longer time delays) if I reinitialise the bus (or only the Interface?) like this:

def notify(appname, sth, icon_path, title, body, callback_array, hints, timeout):
    bus = dbus.SessionBus()
    item = 'org.freedesktop.Notifications'
    dbus_obj  = bus.get_object(item, '/org/freedesktop/Notifications')
    dbus_iface =  dbus.Interface(dbus_obj, item)
    dbus_iface.Notify(appname, sth, icon_path, title, body, callback_array, hints, timeout)

I'm on Debian Jessie / Fluxbox and calling it from Python3.4.2 & python3-notify2 Version: 0.3-3

Feel free to reject the issue if I'm misunderstanding something...

Comments (7)

  1. Thomas Kluyver repo owner

    I'm glad to hear someone is still using this! Unfortunately, I don't know what could be causing the bug you see. Once it's initialised, all notify2 should be doing is calling Notify and CloseNotification on the DBus object, so I don't know why anything should change.

    Possibly it's a bug in python-dbus? But it's also quite possible that I've misunderstood something about DBus - it's pretty complex, and this module is the only thing I've done with it.

  2. Former user Account Deleted

    I fixed it. My method: init again and again before call Notify.

    For example:

    def notify(sleep_time):
        pb=Pixbuf.new_from_file("./icon.png")
        print(sleep_time)
        time.sleep(60*sleep_time)
        n=notify2.Notification("Hello", "I am alive")
        n.set_icon_from_pixbuf(pb)
        n.set_timeout(15000)
        n.show()
    notify2.init("test_app") 
    notify(0)
    notify(5)
    notify(15)
    notify(31)
    notify(55)
    notify(75)
    

    WRONG!

    Too wrong:

    def notify(sleep_time):
        pb=Pixbuf.new_from_file("./icon.png")
        print(sleep_time)
        notify2.init("test_app") 
        time.sleep(60*sleep_time)
        n=notify2.Notification("Hello", "I am alive")
        n.set_icon_from_pixbuf(pb)
        n.set_timeout(15000)
        n.show()
    
    notify(0)
    notify(5)
    notify(15)
    notify(31)
    notify(55)
    notify(75)
    

    Right:

    def notify(sleep_time):
        pb=Pixbuf.new_from_file("./icon.png")
        print(sleep_time)
        time.sleep(60*sleep_time)
        notify2.init("test_app") 
        n=notify2.Notification("Hello", "I am alive")
        n.set_icon_from_pixbuf(pb)
        n.set_timeout(15000)
        n.show()
    
    notify(0)
    notify(5)
    notify(15)
    notify(31)
    notify(55)
    notify(75)
    
  3. Thomas Kluyver repo owner

    I just ran the first example you gave (the one where you said 'WRONG!'), and it completed without an error, showing the notifications as I'd expect. So I'm still not sure what's going on. But I'm glad you've found a solution that works for you. I'm pretty sure there should be no harmful effects of calling init() again.

  4. Former user Account Deleted

    In the first and second example i got except after 31 min. sleep. (After notify(31)). When notify(0), notify(5), notify(15) all good.

    In third example all ok even after 55 min.

  5. Dmytro Poltavchenko

    Hi!

    I have faced with the same issue on Debian 9.5 (stretch). And seems like re-calling notify2.init function helps to avoid this issue.

    Here is an example code:

    import notify2
    
    # notify2.init("test")
    wn = notify2.Notification('test', icon='audio-x-generic')
    
    
    def show_message(subj, body):
        global wn
        notify2.init("test")  # <-- This helps avoid dbus.exceptions.DBusException
        wn.set_timeout(5000)
        wn.update(subj, body)
        wn.show()
    

    I hope this snippet will help to determine where is a bug.

  6. Thomas Kluyver repo owner

    I'm no longer working on notify2, but I did in the meantime create a pure-Python D-Bus library. There's an example for sending a notification here:

    https://gitlab.com/takluyver/jeepney/blob/master/examples/blocking_notify.py

    Notifications are also the example used in the docs:

    https://jeepney.readthedocs.io/en/latest/integrate.html

    This is more verbose than calling notify2 - Jeepney is a D-Bus wrapper, not specifically a notifications wrapper - but you can inspect what the code is doing right down to sending bytes to the D-Bus socket.

    Alternatively, GUI toolkits may have notification support, e.g. libnotify wrapped by GObject introspection. If you're using GTK or Qt already, it's probably best to use the integrated tools for this.

    Finally, if you need to investigate what's happening over D-Bus, you might want to try using Bustle, which can monitor messages and show a diagram of the communication.

  7. Log in to comment