资源简介
2019 Apress出版
The Python programming language adopted a preemptive concurrency
framework in the early 90s via the threading module, which strived to
mimic the Java concurrency library, as per the respective commit message.
A simple but powerful mechanism governs concurrent execution of
bytecode in most Python implementations. This mechanism is called the
GIL (global interpreter lock). The interpreter consumes one bytecode
instruction at a time.
This effectively means that only one thread can run at the same time
(in one interpreter process). Despite this fact, the underlying native thread
implementation might be able to run more than one thread at a time.
The threads are appointed “fair” amounts of CPU time. Without
employing sophisticated introspection techniques, this boils down to
simple/naive time-based scheduling algorithms.
Taking this approach in the past would often yield inferior solutions to
an equivalent single threaded program, for Python implementation with a
GIL like CPython.
Since removing the GIL is not an option,1 and prior attempts like
Python safe-thread2 failed because they degraded the single threading
performance significantly, the concurrency situation meant having only
the threading module
评论
共有 条评论