[Qgis-developer] Bug? Python plug-in threadS seem to run only when Python console is busy.

Mikhail Titov mlt at gmx.us
Tue Jul 24 13:06:44 PDT 2012


Mikhail Titov <mlt-0UDz38MK/Mo at public.gmane.org> writes:

> Mikhail Titov <mlt-0UDz38MK/Mo-XMD5yJDbdMReXY1tMh2IBg at public.gmane.org> writes:
>
>> It seems that the thread I create in my plug-in is mostly dormant unless
>> I have something like time.sleep(alot) running in Python console. Is it
>> normal? I even tried to start QThread with QThread.HighPriority with the
>> same result:(
>
> I'm not sure whether it is buffered IO or actually dormant thread
> causing all the troubles.
>
> The ugly workaround just to make it ticking is to set up 5 seconds
> QTimer in main GUI thread after auxiliary thread is started and use
> time.sleep(10) and QCoreApplication.instance().processEvents() in
> timeout handling slot. The GUI does block during that thus rendering
> entire idea unusable.

I forgot that QTimer uses ms while sleep uses seconds. 2 seconds QTimer
and time.sleep(.1) in handling slot _without_ processEvents() make
everything work just fine.

>> The module itself runs just fine when started outside of QGIS.
>>
>> Am I not supposed to create threads in python plug-ins? I thought it
>> would be better rather than trying to dig around QCoreApplication to
>> process events so GUI is not frozen.
>
> The bottom line is to create C++ plug-ins for multi-threaded tasks :(

Apparently this statement is not quite correct.

-- 
Mikhail


More information about the Qgis-developer mailing list