How are threads implemented in Python?

Moshe Zadka moshez at zadka.site.co.il
Sat Jan 27 11:47:47 EST 2001


On Sat, 27 Jan 2001 16:32:46 GMT, "Parzival Herzog" <parz at home.com> wrote:

> Are threads implemented as OS threads, thereby multi-threading the
> interpreter code, or does the Python interpreter itself maintain a
> list of Python treads and switch between them?

Well, both.
The threads are implemented as OS threads, but Python holds
a global interpreter lock (GIL), and only the thread that
holds the lock gets to run. The lock is released and reaquired
every N instructions.

Some instructions release the lock while waiting for OS activity:
the classical examples being reading from file descriptors or
sockets.
-- 
Moshe Zadka <sig at zadka.site.co.il>
This is a signature anti-virus. 
Please stop the spread of signature viruses!
Fingerprint: 4BD1 7705 EEC0 260A 7F21  4817 C7FC A636 46D0 1BD6




More information about the Python-list mailing list