About GIL Questions!

Chris Angelico rosuav at gmail.com
Thu Jun 20 00:19:39 EDT 2013


On Thu, Jun 20, 2013 at 2:13 PM, Thanatos xiao <yanxiaopei199 at 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



More information about the Python-list mailing list