Clarity: GIL, processes and CPUs etc

Gerhard Häring gh at ghaering.de
Wed Feb 15 12:23:04 EST 2006


adsheehan at eircom.net wrote:
> I have been reading many of the posting on the GIL and impact on 
> threading etc. I have found is confusing and would welcome some
> clarity on this.
> 
> I understand that embedding the interpreter in a C/C++ application 
> limits it to one CPU. If the application is multi-threaded (system
> threads) in will not use additional CPUs as the interpreter is tied
> to one CPU courtesy of the GIL. True or False?

True. More than one CPU can be used if the GIL is released during calls 
to external libraries, though. Well-written C extension modules and the 
Python standard library do this where appropriate. Still only one thread 
can execute pure Python code at a time.

> I understand that forking or running multiple process instances of the
> above application would make use of multiple CPUs. This is because each
> process would have its own interpreter and GIL that is independent of
> any other process.
> True or False? [...]

True.

HTH,

-- Gerhard



More information about the Python-list mailing list