473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Clarity: GIL, processes and CPUs etc

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?

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?

Can anyone clarify the above?

Thanks
A

Feb 15 '06 #1
3 1443
ad*******@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
Feb 15 '06 #2
ad*******@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.

Feb 15 '06 #3
[ad*******@eircom.net]
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, only when a thread is inside pure python code. C-level extensions
and library modules, e.g. I/O modules, release the GIL, thus permitting
other threads in the same process to run simultaneously. But only one
thread can be running *inside the python interpreter* 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. Every separate process will have its own python interpreter,
meaning it has its own GIL. Python code running in multiple processes
can execute truly simultaneously.

So you can run pure python code simultaneously on multiple cpus on a
multi-cpu box by using multiple independent processes. But if your
processes need to communicate, then you need to de/serialise
objects/parameters for transmission between those processes.

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan

Feb 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Canneloni | last post by:
Xeon hyperthreaded CPUs show up as two CPUs in the cpuinfo file. So a dual Xeon machine appears as a quad processor. In Windows, it's the same thing. A dual Xeon will have 4 CPU charts...
2
by: Viviana Vc | last post by:
Hi all, I have a computer with 2 CPUs where I have to build a big project. I am using WinXP and MS Visual Stuio .NET (VC++ 7.1). When I'm building the project one of the CPU is completely taken,...
1
by: AWHK | last post by:
I got 4 virtual CPUs on my computer (xeon processor) and I got this .NET application that runs a lengthy processor intensive task. I have noticed when I start two instances of the application (each...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
1
by: RP | last post by:
Hi all, where can I find some docs on tuning asp.net 1.1 for HT CPUs? We just upgraded our server to a single HT CPU and it appears that the OS still reports 2 CPUs? TIA!
4
by: Klaas Vantournhout | last post by:
Hi, I am currently using OpenMP (gcc 4.2.0) to do parallel computing on a computer with a certain amount of cpu's. I need the total number of cpu's as a variable in my code. So I was...
35
by: Carl J. Van Arsdall | last post by:
Alright, based a on discussion on this mailing list, I've started to wonder, why use threads vs processes. So, If I have a system that has a large area of shared memory, which would be better? ...
1
by: rcamarda | last post by:
I have been unsuccessful locating information about the maximum number of CPU's SQL Server 2005 Enterprise supports. However I did find info in a document about configuring a fail over cluster...
1
by: jazon | last post by:
Let me start by saying this for an Operating Systems class. No, I don't expect the work to be done for me. The assignment is as follows: To be honest, I feel like a fish out of water, like...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.