[PyQt] Threads with PyQt. Qt's or Python's?

Giovanni Bajo rasky at develer.com
Tue Feb 3 15:34:21 GMT 2009


On 2/3/2009 4:19 PM, Frédéric wrote:
> Le 3/2/2009, "Giovanni Bajo" <rasky at develer.com> a écrit:
> 
>> The trick is that a signal/slot connection across a thread is different
>>from a normal one: in a normal connection, slots are called immediately,
>> within the "emit()" call. Instead, in an asynchronous connection, when
>> the signal is emitted, an event is posted to the main thread (posting
>> events is thread-safe); then the receiving thread's exec loop will
>> process the event and call the correct slot.
> 
> In this last case, does the call to emit() immediatly return, and the
> thread go on with the next instruction, or does it wait until the event
> has really called the slot?

Depends on the connection type (which you can manually specify during 
the connect() call, or leave the default).

The default (for connections between different threads) is 
Qt.QueuedConnection, which means that the emit() call exits immediately. 
Otherwise, you can specify Qt.BlockingQueueConnection: the emitting 
thread will wait until the receiving thread has found time to process 
all the slots. Notice that it's easy to deadlock, if you don't pay 
enough attention (and even if you do ;).
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com




More information about the PyQt mailing list