Will multithreading make python less popular?

Graham Dumpleton Graham.Dumpleton at gmail.com
Tue Feb 17 22:47:14 EST 2009


On Feb 16, 9:27 pm, Michele Simionato <michele.simion... at gmail.com>
wrote:
> On Feb 16, 10:34 am, rushen... at gmail.com wrote:
>
>
>
> > Hi everybody,
> > I am an engineer. I am trying to improve my software development
> > abilities. I have started programming with ruby. I like it very much
> > but i want to add something more. According to my previous research i
> > have designed a learning path for myself. It's like something below.
> >       1. Ruby (Mastering as much as possible)
> >       2. Python (Mastering as much as possible)
> >       3. Basic C++ or Basic Java
> > And the story begins here. As i search on the net,  I have found that
> > because of the natural characteristics of python such as GIL, we are
> > not able to write multi threaded programs. Oooops, in a kind of time
> > with lots of cpu cores and we are not able to write multi threaded
> > programs. That is out of fashion. How a such powerful language doesn't
> > support multi threading. That is a big minus for python. But there is
> > something interesting, something like multi processing. But is it a
> > real alternative for multi threading. As i searched it is not, it
> > requires heavy hardware requirements (lots of memory, lots of cpu
> > power). Also it is not easy to implement, too much extra code...
>
> multiprocessing is already implemented for you in the standard
> library.
> Of course it does not require heavy hardware requirements.
>
> > After all of that, i start to think about omiting python from my
> > carrier path and directly choosing c++ or java. But i know google or
> > youtube uses python very much. How can they choose a language which
> > will be killed by multi threading a time in near future. I like python
> > and its syntax, its flexibility.
>
> > What do you think about multi threading and its effect on python. Why
> > does python have such a break and what is the fix. Is it worth to make
> > investment of time and money to a language it can not take advantage
> > of multi cores?
>
> You can take advantage of multi cores, just not with threads but with
> processes,
> which BTW is the right way to go in most situations. So (assuming you
> are not
> a troll) you are just mistaken in thinking that the only way to
> use multicores is via multithreading.

It is also a mistaken belief that you cannot take advantage of multi
cores with multiple threads inside of a single process using Python.

What no one seems to remember is that when calls are made into Python
extension modules implemented in C code, they have the option of
releasing the Python GIL. By releasing the Python GIL at that point,
it would allow other Python threads to run at the same time as
operations are being done in C code in the extension module.

Obviously if the extension module needs to manipulate Python objects
it will not be able to release the GIL, but not all extension modules
are going to be like this and could have quite sizable sections of
code that can run with the GIL released. Thus, you could have many
threads running at the same time in sections of C code, at same time
as well as currently delegated thread within Python code.

A very good example of this is when embeddeding Python inside of
Apache. So much stuff is actually done inside of Apache C code with
the GIL released, that there is more than ample opportunity for
multiple threads to be running across cores at the same time.

Graham




More information about the Python-list mailing list