Grok the GIL (opensource.com)
Here's anopensource.com article describing how the Python global interpreterlock works and some nuances of writing threaded Python code."Although the GIL does not excuse us from the need for locks, it doesmean there is no need for fine-grained locking. In a free-threaded languagelike Java, programmers make an effort to lock shared data for the shortesttime possible, to reduce thread contention and allow maximumparallelism. Because threads cannot run Python in parallel, however,there's no advantage to fine-grained locking. So long as no thread holds alock while it sleeps, does I/O, or some other GIL-dropping operation, youshould use the coarsest, simplest locks possible."