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

Skip to content

Commit d42bc51

Browse files
committed
Add a couple of words about the new GIL implementation
1 parent aee355b commit d42bc51

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Doc/library/sys.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ always available.
282282

283283
Return the interpreter's "check interval"; see :func:`setcheckinterval`.
284284

285+
.. deprecated:: 3.2
286+
Use :func:`getswitchinterval` instead.
287+
285288

286289
.. function:: getdefaultencoding()
287290

@@ -345,6 +348,12 @@ always available.
345348
collector.
346349

347350

351+
.. function:: getswitchinterval()
352+
353+
Return the interpreter's "thread switch interval"; see
354+
:func:`setswitchinterval`.
355+
356+
348357
.. function:: _getframe([depth])
349358

350359
Return a frame object from the call stack. If optional integer *depth* is
@@ -626,6 +635,11 @@ always available.
626635
performance for programs using threads. Setting it to a value ``<=`` 0 checks
627636
every virtual instruction, maximizing responsiveness as well as overhead.
628637

638+
.. deprecated:: 3.2
639+
This function doesn't have an effect anymore, as the internal logic
640+
for thread switching and asynchronous tasks has been rewritten.
641+
Use :func:`setswitchinterval` instead.
642+
629643

630644
.. function:: setdefaultencoding(name)
631645

@@ -689,6 +703,17 @@ always available.
689703
limit can lead to a crash.
690704

691705

706+
.. function:: setswitchinterval(interval)
707+
708+
Set the interpreter's thread switch interval (in seconds). This floating-point
709+
value determines the ideal duration of the "timeslices" allocated to
710+
concurrently running Python threads. Please note that the actual value
711+
can be higher, especially if long-running internal functions or methods
712+
are used. Also, which thread becomes scheduled at the end of the interval
713+
is the operating system's decision. The interpreter doesn't have its
714+
own scheduler.
715+
716+
692717
.. function:: settrace(tracefunc)
693718

694719
.. index::

Doc/whatsnew/3.2.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ New, Improved, and Deprecated Modules
8585
(Contributed by Georg Brandl and Mattias Brändström;
8686
`appspot issue 53094 <http://codereview.appspot.com/53094>`_.)
8787

88+
Multi-threading
89+
===============
90+
91+
* The mechanism for serializing execution of concurrently running Python
92+
threads (generally known as the GIL or Global Interpreter Lock) has been
93+
rewritten. Among the objectives were more predictable switching intervals
94+
and reduced overhead due to lock contention and the number of ensuing
95+
system calls. The notion of a "check interval" to allow thread switches
96+
has been abandoned and replaced by an absolute duration expressed in
97+
seconds. This parameter is tunable through :func:`sys.setswitchinterval()`.
98+
It currently defaults to 5 milliseconds.
99+
100+
Additional details about the implementation can be read from a `python-dev
101+
mailing-list message
102+
<http://mail.python.org/pipermail/python-dev/2009-October/093321.html>`_
103+
(however, "priority requests" as exposed in this message have not been
104+
kept for inclusion).
105+
106+
(Contributed by Antoine Pitrou)
107+
108+
88109
Optimizations
89110
=============
90111

0 commit comments

Comments
 (0)