[capi-sig] Threading in Python

Swapnil.ST at gmail.com Swapnil.ST at gmail.com
Tue Sep 2 09:54:40 CEST 2008


I am working on an application which embeds python in the application  
threads and each thread can further create threads using the python thread  
module
few things i don't understand:
1. why does the interpreter ie the main thread keeps releasing and  
reacquiring the GIL every few instruction. why isn't GIL simply allowed to  
be acquired by any thread which requires it then. I mean why is the  
acquisition and release of a lock kept periodic and not on need basis?(  
which is obviously the way it should be)
2. The purpose of GIL was not very clear to me from python-docs. is it just  
a single lock to guard every global variable? or is it something more?
3. suppose I am not making any blocking call then I would never release GIL  
since that is the only thing guarding my thread state and i don't want my  
thread state messed up any time my thread is running. Which implies  
unacceptable starvation of other threads.


More information about the capi-sig mailing list