[PyKDE] Fatal Python error: PyEval_RestoreThread: NULL tstate

Patrick Stinson ajole-1 at gci.net
Thu Dec 11 23:45:01 GMT 2003


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

Here is my [last] stack trace: (my library is called 'pkaudio')

pkaudio: deregistering module: Global Mixer
Fatal Python error: PyEval_RestoreThread: NULL tstate
WAD: Collecting debugging information...
WAD: Abort.
#19  0x08054ca1 in ?()
#18  0x40173914 in __libc_start_main()
#17  0x401896a0 in __GI_exit()
#16  0x41b27945 in __tcf_1()
#15  0x41b1b4e1 in _ZN2PK6EngineD1Ev()
#14  0x41b22537 in _ZN2PK5MixerD0Ev()
#13  0x41b23674 in _ZN2PK6ModuleD2Ev()
#12  0x41b2841b in _ZN2PK11PassivePortD0Ev()
#11  0x41b27b93 in _ZN2PK4PortD2Ev()
#10  0x41b280b5 in _ZN2PK4Port10DisconnectEv()
#9   0x41b281d1 in _ZN2PK4Port10DisconnectEv()
#8   0x41b4a119 in _ZN12sipPK_Module12DisconnectedEPN2PK4PortE()
#7   0x4001fb64 in sipIsPyMethod()
#6   0x4001b8c2 in sipBlockThreads()				<---- This calls...
#5   0x080b9c92 in PyEval_RestoreThread()		<---- this with an inval. parm.
#4   0x080e838b in Py_AtExit()
#3   0x401885fb in __GI_abort()
#2   0x40187094 in __GI_raise()
#1   0x4003386b in __pthread_raise()
#0   0x401872e1 in __kill()


This is not the only instance of a stack trace that is valid for this problem, 
it bombs in lots of other cases, too. It apears to be sip code that calls 
PyEval_RestoreThread(), which is passed a NULL tstate. After reading some of 
the python threading C API, I've hit a road block.

I originally wrote pthread usage into my lib code, then decided to code it out 
again and start the threads from threads created in python assuming it had 
something to do with the lack of thread state structures described in Section 
'8.1  Thread State and the Global Interpreter Lock' of the C Python API. I'm 
not sure how valid this is, considering the language barrier my code 
trancends.

How would you suggest I approach a problem like this? On a more general note, 
what sort of interaction do C threads have with python thread code/global 
interpreter lock? In designing an audio library that has need for disk, 
audio, and eventually application threads, what approach should I take with 
the creation of threads?

Cheers!




More information about the PyQt mailing list