Status of Python threading support (GIL removal)?

skip at pobox.com skip at pobox.com
Fri Jun 19 13:13:12 EDT 2009


    >> If you know that your (C) code is thread safe on its own, you can
    >> release the GIL around long-running algorithms, thus using as many
    >> CPUs as you have available, in a single process.

    Olivier> what do you mean ?

    Olivier> Cpython can't benefit from multi-core without multiple
    Olivier> processes.

It can, precisely as Martin indicated.  Only one thread at a time can hold
the GIL.  That doesn't mean that multiple threads can't execute.  Suppose
you have two threads, one of which winds up executing some bit of C code
which doesn't mess with the Python run-time at all (say, a matrix multiply).
Before launching into the matrix multiply, the extension module releases the
GIL then performs the multiply.  With the GIL released another thread can
acquire it.  Once the multiply finishes the first thread needs to reacquire
the GIL before executing any calls into the Python runtime or returning.

-- 
Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/
    when i wake up with a heart rate below 40, i head right for the espresso
    machine. -- chaos @ forums.usms.org



More information about the Python-list mailing list