[Pythonmac-SIG] python threading and multiple processors

Ronald Oussoren ronaldoussoren at mac.com
Thu Nov 2 17:36:10 CET 2006


On Nov 2, 2006, at 5:25 PM, David Worrall wrote:

> Hi All,
> Can anyone tell me whether or not the python threading module can
> make use of multiple processors
> (such as on the intel Mac)?

It can, but not always optimally. Python has a global interpreter  
lock (GIL) that is held whenever a thread is executing python byte  
code. This means only one thread at a time can be executing byte  
code, however multiple threads can be in C code at the same time.

Therefore it is possible to use multiple CPUs, but only if you have C  
code that  does some calculation without holding the GIL.  Note that  
several GUI API's from Apple, such as CoreImage make automatic use of  
multiple processors, and even if you don't use multiple processors  
yourself the other processor won't be completely idle, that can and  
will be used for background tasks and other programs.

If you want to make full use of multiple processors using pure python  
code you'll have to use multiple processes.

Ronald

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3562 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20061102/5a7646a1/attachment.bin 


More information about the Pythonmac-SIG mailing list