Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48771

Re: About GIL Questions!

References <CAF0POctYGbN39_B_k9kgrDDqhstvBBDXonTpzkG_Tm7DHwto=Q@mail.gmail.com>
Date 2013-06-20 14:19 +1000
Subject Re: About GIL Questions!
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3607.1371701982.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jun 20, 2013 at 2:13 PM, Thanatos xiao <yanxiaopei199@gmail.com> wrote:
> Hey everyone!
> Recently I see the python source code, but i still not understand about gil.
> first, why single core quicker multi-core ? who can explan this in bottom
> layery ?
> second, what the different between the mult-core  and the single core to
> schecule threads?
>
> thanks!
> Forgive me bad english!

The GIL, massively simplified: One thread at a time can be accessing
Python objects. That means that Python threads are good for I/O-bound
operations (you can have three threads all waiting on the network at
once), but not for CPU-bound operations, unless you're calling on a
library that deliberately releases the GIL.

But if you want to run Python code across multiple cores, you can use
the multiprocessing module, which runs separate Python instances, so
they have separate GILs. You then can share data between them in a few
ways, but they're mostly separate.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: About GIL Questions! Chris Angelico <rosuav@gmail.com> - 2013-06-20 14:19 +1000

csiph-web