Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0034281

Browse files
committed
Elaborate about the GIL.
1 parent f8dc9ca commit 0034281

2 files changed

Lines changed: 35 additions & 13 deletions

File tree

Doc/glossary.rst

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ Glossary
102102
See :pep:`343`.
103103

104104
CPython
105-
The canonical implementation of the Python programming language. The
106-
term "CPython" is used in contexts when necessary to distinguish this
107-
implementation from others such as Jython or IronPython.
105+
The canonical implementation of the Python programming language, as
106+
distributed on `python.org <http://python.org>`_. The term "CPython"
107+
is used when necessary to distinguish this implementation from others
108+
such as Jython or IronPython.
108109

109110
decorator
110111
A function returning another function, usually applied as a function
@@ -263,16 +264,25 @@ Glossary
263264
See :term:`global interpreter lock`.
264265

265266
global interpreter lock
266-
The lock used by Python threads to assure that only one thread
267-
executes in the :term:`CPython` :term:`virtual machine` at a time.
268-
This simplifies the CPython implementation by assuring that no two
269-
processes can access the same memory at the same time. Locking the
270-
entire interpreter makes it easier for the interpreter to be
271-
multi-threaded, at the expense of much of the parallelism afforded by
272-
multi-processor machines. Efforts have been made in the past to
273-
create a "free-threaded" interpreter (one which locks shared data at a
274-
much finer granularity), but so far none have been successful because
275-
performance suffered in the common single-processor case.
267+
The mechanism used by the :term:`CPython` interpreter to assure that
268+
only one thread executes Python :term:`bytecode` at a time.
269+
This simplifies the CPython implementation by making the object model
270+
(including critical built-in types such as :class:`dict`) implicitly
271+
safe against concurrent access. Locking the entire interpreter
272+
makes it easier for the interpreter to be multi-threaded, at the
273+
expense of much of the parallelism afforded by multi-processor
274+
machines.
275+
276+
However, some extension modules, either standard or third-party,
277+
are designed so as to release the GIL when doing computationally-intensive
278+
tasks such as compression or hashing. Also, the GIL is always released
279+
when doing I/O.
280+
281+
Past efforts to create a "free-threaded" interpreter (one which locks
282+
shared data at a much finer granularity) have not been successful
283+
because performance suffered in the common single-processor case. It
284+
is believed that overcoming this performance issue would make the
285+
implementation much more complicated and therefore costlier to maintain.
276286

277287
hashable
278288
An object is *hashable* if it has a hash value which never changes during

Doc/library/threading.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@ The :mod:`dummy_threading` module is provided for situations where
1717
methods and functions in this module in the Python 2.x series are still
1818
supported by this module.
1919

20+
.. impl-detail::
21+
22+
Due to the :term:`Global Interpreter Lock`, in CPython only one thread
23+
can execute Python code at once (even though certain performance-oriented
24+
libraries might overcome this limitation).
25+
If you want your application to make better of use of the computational
26+
resources of multi-core machines, you are advised to use
27+
:mod:`multiprocessing` or :class:`concurrent.futures.ProcessPoolExecutor`.
28+
However, threading is still an appropriate model if you want to run
29+
multiple I/O-bound tasks simultaneously.
30+
2031
.. seealso::
2132

2233
Latest version of the :source:`threading module Python source code
2334
<Lib/threading.py>`
2435

36+
2537
This module defines the following functions and objects:
2638

2739

0 commit comments

Comments
 (0)