Skip to content

Commit 12f6175

Browse files
committed
Merge branch 'master' into pegen
2 parents 1d2b107 + 25e580a commit 12f6175

File tree

89 files changed

+1083
-577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1083
-577
lines changed

Doc/c-api/init.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,18 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
10721072
to :c:func:`PyThreadState_Clear`.
10731073
10741074
1075+
.. c:function:: PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate)
1076+
1077+
Get the current frame of the Python thread state *tstate*. It can be
1078+
``NULL`` if no frame is currently executing.
1079+
1080+
See also :c:func:`PyEval_GetFrame`.
1081+
1082+
*tstate* must not be ``NULL``.
1083+
1084+
.. versionadded:: 3.9
1085+
1086+
10751087
.. c:function:: PyInterpreterState* PyThreadState_GetInterpreter(PyThreadState *tstate)
10761088
10771089
Get the interpreter of the Python thread state *tstate*.
@@ -1389,6 +1401,10 @@ pointer and a void pointer argument.
13891401
This function doesn't need a current thread state to run, and it doesn't
13901402
need the global interpreter lock.
13911403
1404+
To call this function in a subinterpreter, the caller must hold the GIL.
1405+
Otherwise, the function *func* can be scheduled to be called from the wrong
1406+
interpreter.
1407+
13921408
.. warning::
13931409
This is a low-level function, only useful for very special cases.
13941410
There is no guarantee that *func* will be called as quick as
@@ -1397,6 +1413,12 @@ pointer and a void pointer argument.
13971413
function is generally **not** suitable for calling Python code from
13981414
arbitrary C threads. Instead, use the :ref:`PyGILState API<gilstate>`.
13991415
1416+
.. versionchanged:: 3.9
1417+
If this function is called in a subinterpreter, the function *func* is
1418+
now scheduled to be called from the subinterpreter, rather than being
1419+
called from the main interpreter. Each subinterpreter now has its own
1420+
list of scheduled calls.
1421+
14001422
.. versionadded:: 3.1
14011423
14021424
.. _profiling:

Doc/c-api/module.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ state:
441441
442442
Add an object to *module* as *name*. This is a convenience function which can
443443
be used from the module's initialization function. This steals a reference to
444-
*value* on success. Return ``-1`` on error, ``0`` on success.
444+
*value* on success. Return ``-1`` on error, ``0`` on success.
445445
446446
.. note::
447447
@@ -484,6 +484,16 @@ state:
484484
485485
Add a string constant to *module*.
486486
487+
.. c:function:: int PyModule_AddType(PyObject *module, PyTypeObject *type)
488+
489+
Add a type object to *module*.
490+
The type object is finalized by calling internally :c:func:`PyType_Ready`.
491+
The name of the type object is taken from the last component of
492+
:c:member:`~PyTypeObject.tp_name` after dot.
493+
Return ``-1`` on error, ``0`` on success.
494+
495+
.. versionadded:: 3.9
496+
487497
488498
Module lookup
489499
^^^^^^^^^^^^^

Doc/c-api/reflection.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@
55
Reflection
66
==========
77

8-
.. c:function:: PyObject* PyEval_GetBuiltins()
8+
.. c:function:: PyObject* PyEval_GetBuiltins(void)
99
1010
Return a dictionary of the builtins in the current execution frame,
1111
or the interpreter of the thread state if no frame is currently executing.
1212
1313
14-
.. c:function:: PyObject* PyEval_GetLocals()
14+
.. c:function:: PyObject* PyEval_GetLocals(void)
1515
1616
Return a dictionary of the local variables in the current execution frame,
1717
or ``NULL`` if no frame is currently executing.
1818
1919
20-
.. c:function:: PyObject* PyEval_GetGlobals()
20+
.. c:function:: PyObject* PyEval_GetGlobals(void)
2121
2222
Return a dictionary of the global variables in the current execution frame,
2323
or ``NULL`` if no frame is currently executing.
2424
2525
26-
.. c:function:: PyFrameObject* PyEval_GetFrame()
26+
.. c:function:: PyFrameObject* PyEval_GetFrame(void)
2727
2828
Return the current thread state's frame, which is ``NULL`` if no frame is
2929
currently executing.
3030
31+
See also :c:func:`PyThreadState_GetFrame`.
32+
3133
3234
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)
3335

Doc/library/collections.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ The class can be used to simulate nested scopes and is useful in templating.
116116
>>> list(combined)
117117
['music', 'art', 'opera']
118118

119+
.. versionchanged:: 3.9
120+
Added support for ``|`` and ``|=`` operators, specified in :pep:`584`.
121+
119122
.. seealso::
120123

121124
* The `MultiContext class

Doc/library/functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ are always available. They are listed here in alphabetical order.
13111311
the second argument to be negative, permitting computation of modular
13121312
inverses.
13131313

1314-
.. versionchanged:: 3.9
1314+
.. versionchanged:: 3.8
13151315
Allow keyword arguments. Formerly, only positional arguments were
13161316
supported.
13171317

Doc/library/signal.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ This has consequences:
5353
Signals and threads
5454
^^^^^^^^^^^^^^^^^^^
5555

56-
Python signal handlers are always executed in the main Python thread,
56+
Python signal handlers are always executed in the main Python thread of the main interpreter,
5757
even if the signal was received in another thread. This means that signals
5858
can't be used as a means of inter-thread communication. You can use
5959
the synchronization primitives from the :mod:`threading` module instead.
6060

61-
Besides, only the main thread is allowed to set a new signal handler.
61+
Besides, only the main thread of the main interpreter is allowed to set a new signal handler.
6262

6363

6464
Module contents
@@ -266,7 +266,7 @@ The :mod:`signal` module defines the following functions:
266266
same process as the caller. The target thread can be executing any code
267267
(Python or not). However, if the target thread is executing the Python
268268
interpreter, the Python signal handlers will be :ref:`executed by the main
269-
thread <signals-and-threads>`. Therefore, the only point of sending a
269+
thread of the main interpreter <signals-and-threads>`. Therefore, the only point of sending a
270270
signal to a particular Python thread would be to force a running system call
271271
to fail with :exc:`InterruptedError`.
272272

@@ -360,7 +360,8 @@ The :mod:`signal` module defines the following functions:
360360
If not -1, *fd* must be non-blocking. It is up to the library to remove
361361
any bytes from *fd* before calling poll or select again.
362362

363-
When threads are enabled, this function can only be called from the main thread;
363+
When threads are enabled, this function can only be called
364+
from :ref:`the main thread of the main interpreter <signals-and-threads>`;
364365
attempting to call it from other threads will cause a :exc:`ValueError`
365366
exception to be raised.
366367

@@ -413,7 +414,8 @@ The :mod:`signal` module defines the following functions:
413414
signal handler will be returned (see the description of :func:`getsignal`
414415
above). (See the Unix man page :manpage:`signal(2)` for further information.)
415416

416-
When threads are enabled, this function can only be called from the main thread;
417+
When threads are enabled, this function can only be called
418+
from :ref:`the main thread of the main interpreter <signals-and-threads>`;
417419
attempting to call it from other threads will cause a :exc:`ValueError`
418420
exception to be raised.
419421

Doc/library/socketserver.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ Server Objects
237237
.. method:: shutdown()
238238

239239
Tell the :meth:`serve_forever` loop to stop and wait until it does.
240+
:meth:`shutdown` must be called while :meth:`serve_forever` is running in a
241+
different thread otherwise it will deadlock.
240242

241243

242244
.. method:: server_close()

Doc/library/sqlite3.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ Module functions and constants
165165
that 'mytype' is the type of the column. It will try to find an entry of
166166
'mytype' in the converters dictionary and then use the converter function found
167167
there to return the value. The column name found in :attr:`Cursor.description`
168-
is only the first word of the column name, i. e. if you use something like
169-
``'as "x [datetime]"'`` in your SQL, then we will parse out everything until the
170-
first blank for the column name: the column name would simply be "x".
168+
does not include the type, i. e. if you use something like
169+
``'as "Expiration date [datetime]"'`` in your SQL, then we will parse out
170+
everything until the first ``'['`` for the column name and strip
171+
the preceeding space: the column name would simply be "Expiration date".
171172

172173

173174
.. function:: connect(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements, uri])

Doc/library/weakref.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ Extension types can easily be made to support weak references; see
171171
performed by the program during iteration may cause items in the
172172
dictionary to vanish "by magic" (as a side effect of garbage collection).
173173

174+
.. versionchanged:: 3.9
175+
Added support for ``|`` and ``|=`` operators, specified in :pep:`584`.
176+
174177
:class:`WeakKeyDictionary` objects have an additional method that
175178
exposes the internal references directly. The references are not guaranteed to
176179
be "live" at the time they are used, so the result of calling the references

Doc/whatsnew/3.9.rst

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,25 @@ Optimizations
411411

412412
(Contributed by Serhiy Storchaka in :issue:`32856`.)
413413

414+
* Optimize signal handling in multithreaded applications. If a thread different
415+
than the main thread gets a signal, the bytecode evaluation loop is no longer
416+
interrupted at each bytecode instruction to check for pending signals which
417+
cannot be handled. Only the main thread of the main interpreter can handle
418+
signals.
419+
420+
Previously, the bytecode evaluation loop was interrupted at each instruction
421+
until the main thread handles signals.
422+
(Contributed by Victor Stinner in :issue:`40010`.)
423+
414424

415425
Build and C API Changes
416426
=======================
417427

418428
* New :c:func:`PyThreadState_GetInterpreter` and
419429
:c:func:`PyInterpreterState_Get` functions to get the interpreter.
430+
New :c:func:`PyThreadState_GetFrame` function to get the current frame of a
431+
Python thread state.
432+
(Contributed by Victor Stinner in :issue:`39947`.)
420433

421434
* Add ``--with-platlibdir`` option to the ``configure`` script: name of the
422435
platform-specific library directory, stored in the new :attr:`sys.platlibdir`
@@ -514,6 +527,19 @@ Build and C API Changes
514527

515528
Extension modules without module state (``m_size <= 0``) are not affected.
516529

530+
* If :c:func:`Py_AddPendingCall` is called in a subinterpreter, the function is
531+
now scheduled to be called from the subinterpreter, rather than being called
532+
from the main interpreter. Each subinterpreter now has its own list of
533+
scheduled calls.
534+
(Contributed by Victor Stinner in :issue:`39984`.)
535+
536+
* Remove ``_PyRuntime.getframe`` hook and remove ``_PyThreadState_GetFrame``
537+
macro which was an alias to ``_PyRuntime.getframe``. They were only exposed
538+
by the internal C API. Remove also ``PyThreadFrameGetter`` type.
539+
(Contributed by Victor Stinner in :issue:`39946`.)
540+
541+
* The :c:func:`PyModule_AddType` function is added to help adding a type to a module.
542+
(Contributed by Dong-hee Na in :issue:`40024`.)
517543

518544
Deprecated
519545
==========
@@ -567,12 +593,19 @@ Deprecated
567593

568594
(Contributed by Victor Stinner in :issue:`39353`.)
569595

570-
* :mod:`ast` classes ``Index`` and ``ExtSlice`` are considered deprecated
596+
* :mod:`ast` classes ``slice``, ``Index`` and ``ExtSlice`` are considered deprecated
571597
and will be removed in future Python versions. ``value`` itself should be
572598
used instead of ``Index(value)``. ``Tuple(slices, Load())`` should be
573599
used instead of ``ExtSlice(slices)``.
574600
(Contributed by Serhiy Storchaka in :issue:`32892`.)
575601

602+
* :mod:`ast` classes ``Suite``, ``Param``, ``AugLoad`` and ``AugStore``
603+
are considered deprecated and will be removed in future Python versions.
604+
They were not generated by the parser and not accepted by the code
605+
generator in Python 3.
606+
(Contributed by Batuhan Taskaya in :issue:`39639` and :issue:`39969`
607+
and Serhiy Storchaka in :issue:`39988`.)
608+
576609
* The :c:func:`PyEval_InitThreads` and :c:func:`PyEval_ThreadsInitialized`
577610
functions are now deprecated and will be removed in Python 3.11. Calling
578611
:c:func:`PyEval_InitThreads` now does nothing. The :term:`GIL` is initialized
@@ -678,11 +711,6 @@ Removed
678711
defining ``COUNT_ALLOCS`` macro.
679712
(Contributed by Victor Stinner in :issue:`39489`.)
680713

681-
* The ``ast.Suite``, ``ast.Param``, ``ast.AugLoad`` and ``ast.AugStore``
682-
node classes have been removed due to no longer being needed.
683-
(Contributed by Batuhan Taskaya in :issue:`39639` and :issue:`39969`
684-
and Serhiy Storchaka in :issue:`39988`.)
685-
686714

687715
Porting to Python 3.9
688716
=====================

0 commit comments

Comments
 (0)