traceback from hg serve
Greg Ward
greg at gerg.ca
Wed Apr 30 01:55:57 UTC 2014
On 28 April 2014, James Gregory said:
> Does the GIL allow a thread context switch whenever a C library call
> is made? If so then my previous statement about the GIL is nonsense,
> as there are countless opportunities for context switching in just
> about any code. I'm not a Python developer so I don't really know what
> I'm talking about.
Getting dangerously off-topic, and I'm no expert here, but the GIL
simply guarantees no context switches while a single Python opcode is
executing. Consider the code
b = a + 1
That compiles to four opcodes in Python's stack-based VM:
2 0 LOAD_FAST 0 (a)
3 LOAD_CONST 1 (1)
6 BINARY_ADD
7 STORE_FAST 1 (b)
so there are three places where we might context switch while
executing "b = a + 1".
However, the GIL guarantees that we will not context-switch while
computing "a + 1", i.e. while BINARY_ADD is executing. But that
BINARY_ADD might be adding two integers, or it might be adding 1 to
every element of a million-element matrix. That's what makes Python
fun to program and hard to compile. ;-)
Greg
--
Greg Ward http://www.gerg.ca
<greg at gerg.ca> @gergdotca
More information about the Mercurial
mailing list