[PyKDE] Fatal Python error: PyEval_RestoreThread: NULL tstate

Myddrin myddrin at myddrin.com
Fri Dec 12 00:42:02 GMT 2003


On Wednesday 10 December 2003 5:24 pm, Patrick Stinson wrote:
> In coding an audio library that requires the use of different threads
> (audio streaming, disk buffering, application), I've run into similar
> unexplainable (to me) fatal python errors involving the useage of the C
> Python API. the python interpreter spits out
>
> Fatal Python error: PyEval_RestoreThread: NULL tstate
>

I've encountered the same.  If you take a look (carefully) at the PyQT docs on 
riverbank you'll see a brief set of rules.  What it boils down to is the more 
seperated you can keep your QT calls from non-QT threads, the better.  I've 
also seen random freezes and so forth if you aren't extremely careful.

Personaly, I've found that useing a python Queue object to bridge the gap 
between a python queue and a QThread works well.  Then you just use postEvent 
to send the message on to your UI thread.  We've put in a couple hundred 
hours of testing on this solution and it seems to work well.  (And not nearly 
as slowly as you would think!)

Cheezy ASCII are warning (May not look good in some email clients, sorry):
C Thread			Queue			QThread
-----------------------------------------------------------------
								Does blocking get on Queue
								|
								|
								|
C Thread puts ---------->Queue  --------------->Get value
value on to Q 		 passes 			|
				to QThread			|
								Create QCustomEvent
								|
								|
								Post Event
								|
								|
								Loop back.






More information about the PyQt mailing list