On Tue, Jul 24, 2012 at 12:28 AM, Mikhail Titov <[email protected]> wrote: > All: > > I am writing a multi-threaded python plug-in. It is meant to slowly > extract data from NLDAS-2 for selected features using OPeNDAP in the > background as I don't want to block GUI. > > 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:(
Hi Mikhail It has to do with Python's Global Interpreter Lock (GIL). The main GUI thread holds the lock all the time, that's why code in other python thread does not run. Doing something in python console helps because when python runs any commands, it releases and re-acquires the lock every now and then - but when it does not run, the lock is being held. If I remember correctly, I have managed to solve this issue (with some more) in threading branch by calling PyEval_InitThreads() and PyEval_SaveThread() from QgsPythonUtilsImpl::initPython(). Other c++ functions doing python API calls then have to always acquire GIL and release it afterwards with PyGILState_Ensure() and PyGILState_Release( gstate ). These changes probably have to be ported in order to have working Python threads in QGIS, e.g. from Alex's port of threading branch: https://github.com/alexbruy/Quantum-GIS/blob/adopt-threading/src/python/qgspythonutilsimpl.cpp Martin _______________________________________________ Qgis-developer mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
