Python Signal Emitter Race Condition Question

Jim Kytola kytolaj at gmail.com
Wed Aug 1 08:54:32 PDT 2007


I should have been more clear. Forgive the large text dump here, but I'm not
certain how to better explain what I'm seeing. Below is the output of
dbus-monitor, the first clip from a successful run, the second from a failed
run. In one terminal I launch dbus-monitor and in another I execute 'python
tbird.py'.

You'll notice (where I've marked with '*****') that in the failed run, the
NewMail signal comes before GetNameOwner (which I meant in my first post as
the point were things are fully registered), but that in the successful run,
GetNameOwner comes before the call to NewMail.

For full disclosure, I have another script that listens for NameOwnerChanged
and when it finds the org.mozilla.thunderbird.DBus change, connects a
callback function to the NewMail signal - so by successful run, I mean the
callback function gets fired. It's certainly possible that my problem is on
that side, but it does seem strange that I'm seeing the NewMail signal
before the GetNameOwner method call in the bad run.

I noticed that when running the command you used, I see no GetNameOwner call
- is this a sign that the problem is on the other end (is GetNameOwner a
result of connecting the callback function)?

Thanks for your help,
Jim

dbus-monitor output below:

--------------------------------------------------------
Successful Run:
--------------------------------------------------------
signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string ":1.40"
   string ""
   string ":1.40"

method call sender=:1.40 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=Hello

signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string "org.mozilla.thunderbird.DBus"
   string ""
   string ":1.40"

method call sender=:1.40 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=RequestName
   string "org.mozilla.thunderbird.DBus"
   uint32 0

method call sender=:1.33 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus.Introspectable; member=Introspect

*******
method call sender=:1.33 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=GetNameOwner
   string "org.mozilla.thunderbird.DBus"

method call sender=:1.33 ->
dest=:1.40path=/org/mozilla/thunderbird/DBus/NewMail; interface=
org.freedesktop.DBus.Introspectable; member=Introspect

method call sender=:1.33 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=AddMatch
   string "type='signal',sender=':1.40
',path='/org/mozilla/thunderbird/DBus/NewMail',interface='
org.mozilla.thunderbird.DBus',member='NewMail'"

signal sender=:1.40 -> dest=(null destination)
path=/org/mozilla/thunderbird/DBus/NewMail; interface=
org.mozilla.thunderbird.DBus; member=NewMail
   string "test"
   string "test"

signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string "org.mozilla.thunderbird.DBus"
   string ":1.40"
   string ""

signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string ":1.40"
   string ":1.40"
   string ""

--------------------------------------------------------
Bad Run:
--------------------------------------------------------
signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string ":1.35"
   string ""
   string ":1.35"

method call sender=:1.35 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=Hello

signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string "org.mozilla.thunderbird.DBus"
   string ""
   string ":1.35"

method call sender=:1.35 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=RequestName
   string "org.mozilla.thunderbird.DBus"
   uint32 0

method call sender=:1.33 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus.Introspectable; member=Introspect

*******
signal sender=:1.35 -> dest=(null destination)
path=/org/mozilla/thunderbird/DBus/NewMail; interface=
org.mozilla.thunderbird.DBus; member=NewMail
   string "test"
   string "test"

method call sender=:1.33 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=GetNameOwner
   string "org.mozilla.thunderbird.DBus"

method call sender=:1.33 ->
dest=:1.35path=/org/mozilla/thunderbird/DBus/NewMail; interface=
org.freedesktop.DBus.Introspectable; member=Introspect

method call sender=:1.33 ->
dest=org.freedesktop.DBuspath=/org/freedesktop/DBus; interface=
org.freedesktop.DBus; member=AddMatch
   string "type='signal',sender=':1.35',path='/org/mozilla/thunderbird/DBus/
NewMail',interface='org.mozilla.thunderbird.DBus',member='NewMail'"

signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string "org.mozilla.thunderbird.DBus"
   string ":1.35"
   string ""

signal sender=org.freedesktop.DBus -> dest=(null destination)
path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
member=NameOwnerChanged
   string ":1.35"
   string ":1.35"
   string ""


On 8/1/07, Simon McVittie <simon.mcvittie at collabora.co.uk> wrote:
>
> On Wed, 01 Aug 2007 at 09:41:09 -0400, Jim Kytola wrote:
> > 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?
>
> What do you mean by "fully registered"?
>
> Test case: if I remove the time.sleep() call from your code and run:
>
>     dbus-launch sh -c 'dbus-monitor & sleep 1; python tbird.py; sleep 1'
>
> I see events in this order:
>
> signal NameOwnerChanged, name=:1.1, old="", new=:1.1 (tbird.py joins bus)
> signal NameOwnerChanged, name=org.mozilla.thunderbird.DBus, old="", new=:
> 1.1
>     (tbird.py is given its desired bus name)
> signal NewMail (tbird.py emits its signal)
> signal NameOwnerChanged, name=org.mozilla.thunderbird.DBus, old=:1.1,
> new=""
>     (tbird.py releases its bus name during shutdown)
> signal NameOwnerChanged, name=:1.1, old=:1.1, new="" (tbird.py leaves bus)
>
> This looks to me like the desired behaviour. What's the problem?
>
>         Simon
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20070801/5e701e00/attachment-0001.htm 


More information about the dbus mailing list