Grok the GIL (opensource.com)

By corbet Here’s an
opensource.com article
describing how the Python global interpreter
lock works and some nuances of writing threaded Python code.
Although the GIL does not excuse us from the need for locks, it does
mean there is no need for fine-grained locking. In a free-threaded language
like Java, programmers make an effort to lock shared data for the shortest
time possible, to reduce thread contention and allow maximum
parallelism. Because threads cannot run Python in parallel, however,
there’s no advantage to fine-grained locking. So long as no thread holds a
lock while it sleeps, does I/O, or some other GIL-dropping operation, you
should use the coarsest, simplest locks possible.

From: LWN

Share