Python Signal Emitter Race Condition Question

Jim Kytola kytolaj at gmail.com
Wed Aug 1 06:41:09 PDT 2007


Hello,

I have been trying to implement a signal emitter in python (to be used in a
Thunderbird extension), but have run into a bit of a race condition.

Using the below code (without the sleep call) I would almost always see the
call to my emitter function before the object was fully registered on the
dbus. If I add the sleep call, it works, however, the sleep (like I would
expect) causes Thunderbird to hang for that time. Am I missing something
here - does anyone have any suggestions for a better way to do what I'm
trying to do?

Thanks,
Jim

-----------------------------------

import dbus
import dbus.service
import time
from dbus.mainloop.glib import DBusGMainLoop

THUNDERBIRD_DBUS_INTERFACE = 'org.mozilla.thunderbird.DBus'
THUNDERBIRD_DBUS_PATH = '/org/mozilla/thunderbird/DBus/NewMail'

class ThunderBirdDBus(dbus.service.Object):
    def __init__(self, bus_name):
        dbus.service.Object.__init__(self, bus_name, THUNDERBIRD_DBUS_PATH)

    @dbus.service.signal(dbus_interface=THUNDERBIRD_DBUS_INTERFACE,
signature='ss')
    def NewMail(self, from_addr, subject):
        pass


dbus_loop = DBusGMainLoop()
name = dbus.service.BusName(THUNDERBIRD_DBUS_INTERFACE, bus=dbus.SessionBus
(mainloop=dbus_loop))

e = ThunderBirdDBus(name)
time.sleep(2)
e.NewMail("test", "test")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20070801/d0273707/attachment.htm 


More information about the dbus mailing list