Clarity: GIL, processes and CPUs etc

Nick Smallbone nick.smallbone at gmail.com
Wed Feb 15 12:22:09 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?
>

As I understand it, the interpreter needs the GIL held in order to run.
That means that you can only run Python code on one CPU at once, but
plain C/C++ code can be multithreaded.

> 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?
>

I suppose it would, yes. But this is just like running multiple copies
of Python, in that you won't be able to use PyObject *s from one
instance in another directly, so the multiple processes would have to
communicate by sockets or IPC or some other way.




More information about the Python-list mailing list