Python Threads on Linux

Tim Peters at
Wed Aug 1 00:28:14 CEST 2001

[David Lees]
> Question - Does this affect the global lock at all?

You better hope not!

> Is it some way to get around it?  I wrote some simple threaded code
> while back that ran on a dual processor board.  The global lock kept 2
> threads from running in parallel on separate processors.

That's its purpose:  the CPython implementation relies on the GIL to keep
your Python objects sane.  Consider what would happen if, e.g., two threads
mucked with the internal refcount of an object at the same time.

Python releases the GIL only around potentially-blocking and thread-safe C
library calls (like I/O and time.sleep()), and every sys.setcheckinterval()
bytecodes to give another Python thread a chance to run.  If you want it
released at any other time, the only way is to write a C extension module.
However, even then a thread can *never* call a Python C/API function (with a
very few exceptions) unless it holds the GIL at the time.

More information about the Python-list mailing list