Python Signal Emitter Race Condition Question

Havoc Pennington hp at redhat.com
Wed Aug 1 11:08:59 PDT 2007


Thiago Macieira wrote:
> Jim Kytola wrote:
>> 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.
> 
> This is your problem: you're waiting for the application to register.
> 
> Don't.
> 
> Connect the signal as soon as the listener starts. When the application 
> starts, register and emits the signal, your listener will have already 
> set everything up. In fact, it won't even need to listen for the 
> NameOwnerChanged signal.
> 

To add to this a bit, whenever you connect to a signal *after* the 
emitter exists you need to use this pattern:

  1) connect to signal
  2) request the current state that would be notified about by the signal

(in that order)

Any API with signals must have a way to do 2) or it's broken, because an 
app can't connect race-free.

But Thiago is certainly right that you need not wait for the bus name to 
exist before you match for signals on it.

Havoc


More information about the dbus mailing list