Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ Printing and clearing
.. versionadded:: 3.12


.. c:function:: void PyErr_Display(PyObject *unused, PyObject *value, PyObject *tb)

Legacy variant of :c:func:`PyErr_DisplayException`.

Print the exception *value* with its traceback to :data:`sys.stderr`.
If *value* has no traceback set, *tb* is used as its traceback.
The first argument is ignored.

If :data:`sys.stderr` is ``None``, nothing is printed.
If :data:`sys.stderr` is not set, the exception is dumped to the
C ``stderr`` stream instead.

.. deprecated:: 3.12
Use :c:func:`PyErr_DisplayException` instead.

Raising exceptions
==================

Expand Down
9 changes: 4 additions & 5 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,9 @@ PyConfig

.. c:member:: wchar_t* base_executable

Python base executable: :data:`sys._base_executable`.
Python base executable: ``sys._base_executable``.

Set by the :envvar:`__PYVENV_LAUNCHER__` environment variable.
Set by the ``__PYVENV_LAUNCHER__`` environment variable.

Set from :c:member:`PyConfig.executable` if ``NULL``.

Expand Down Expand Up @@ -1748,7 +1748,7 @@ PyConfig

* On macOS, use :envvar:`PYTHONEXECUTABLE` environment variable if set.
* If the ``WITH_NEXT_FRAMEWORK`` macro is defined, use
:envvar:`__PYVENV_LAUNCHER__` environment variable if set.
``__PYVENV_LAUNCHER__`` environment variable if set.
* Use ``argv[0]`` of :c:member:`~PyConfig.argv` if available and
non-empty.
* Otherwise, use ``L"python"`` on Windows, or ``L"python3"`` on other
Expand Down Expand Up @@ -1984,8 +1984,7 @@ PyConfig

The :mod:`warnings` module adds :data:`sys.warnoptions` in the reverse
order: the last :c:member:`PyConfig.warnoptions` item becomes the first
item of :data:`warnings.filters` which is checked first (highest
priority).
item of ``warnings.filters`` which is checked first (highest priority).

The :option:`-W` command line options adds its value to
:c:member:`~PyConfig.warnoptions`, it can be used multiple times.
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ when defined by the compiler, will also implicitly enable :c:macro:`!Py_DEBUG`.
In addition to the reference count debugging described below, extra checks are
performed. See :ref:`Python Debug Build <debug-build>` for more details.

Defining :c:macro:`Py_TRACE_REFS` enables reference tracing
Defining ``Py_TRACE_REFS`` enables reference tracing
(see the :option:`configure --with-trace-refs option <--with-trace-refs>`).
When defined, a circular doubly linked list of active objects is maintained by adding two extra
fields to every :c:type:`PyObject`. Total allocations are tracked as well. Upon
Expand Down
8 changes: 8 additions & 0 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ unless it is :exc:`asyncio.CancelledError`,
is also included in the exception group.
The same special case is made for
:exc:`KeyboardInterrupt` and :exc:`SystemExit` as in the previous paragraph.
There is an additional special case made only for the body of the
``async with``: if it raises :exc:`GeneratorExit` and none of the
other tasks raise exceptions that would be reported, then the
:exc:`GeneratorExit` is reraised.

Task groups are careful not to mix up the internal cancellation used to
"wake up" their :meth:`~object.__aexit__` with cancellation requests
Expand All @@ -456,6 +460,10 @@ reported by :meth:`asyncio.Task.cancelling`.
Improved handling of simultaneous internal and external cancellations
and correct preservation of cancellation counts.

.. versionchanged:: 3.15

Addition of the special case for :exc:`GeneratorExit`.

Sleeping
========

Expand Down
19 changes: 17 additions & 2 deletions Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,7 @@ with the :class:`Pool` class.
Callbacks should complete immediately since otherwise the thread which
handles the results will get blocked.

.. method:: imap(func, iterable[, chunksize])
.. method:: imap(func, iterable, chunksize=1, *, buffersize=None)

A lazier version of :meth:`.map`.

Expand All @@ -2550,12 +2550,27 @@ with the :class:`Pool` class.
``next(timeout)`` will raise :exc:`multiprocessing.TimeoutError` if the
result cannot be returned within *timeout* seconds.

.. method:: imap_unordered(func, iterable[, chunksize])
The *iterable* is collected immediately rather than lazily, unless a
*buffersize* is specified to limit the number of submitted tasks whose
results have not yet been yielded. If the buffer is full, iteration over
the *iterables* pauses until a result is yielded from the buffer.
To fully utilize pool's capacity when using this feature,
set *buffersize* at least to the number of processes in pool
(to consume *iterable* as you go), or even higher
(to prefetch the next ``N=buffersize-processes`` arguments).

.. versionchanged:: next
Added the *buffersize* parameter.

.. method:: imap_unordered(func, iterable, chunksize=1, *, buffersize=None)

The same as :meth:`imap` except that the ordering of the results from the
returned iterator should be considered arbitrary. (Only when there is
only one worker process is the order guaranteed to be "correct".)

.. versionchanged:: next
Added the *buffersize* parameter.

.. method:: starmap(func, iterable[, chunksize])

Like :meth:`~multiprocessing.pool.Pool.map` except that the
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,9 @@ process and user.
Returns information identifying the current operating system.
The return value is a :class:`uname_result`.

On macOS, iOS and Android, this returns the *kernel* name and version (i.e.,
On macOS, iOS and Android, this returns the *kernel* name and release (i.e.,
``'Darwin'`` on macOS and iOS; ``'Linux'`` on Android). :func:`platform.uname`
can be used to get the user-facing operating system name and version on iOS and
can be used to get the user-facing operating system name and release on iOS and
Android.

.. seealso::
Expand Down
5 changes: 2 additions & 3 deletions Doc/library/platform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Cross platform
Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'``. An empty string is
returned if the value cannot be determined.

On iOS and Android, this is the user-facing OS release. To obtain the
Darwin or Linux kernel release, use :func:`os.uname`.

.. function:: system()

Expand All @@ -163,9 +165,6 @@ Cross platform
Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
returned if the value cannot be determined.

On iOS and Android, this is the user-facing OS version. To obtain the
Darwin or Linux kernel version, use :func:`os.uname`.

.. function:: uname()

Fairly portable uname interface. Returns a :func:`~collections.namedtuple`
Expand Down
3 changes: 0 additions & 3 deletions Doc/tools/.nitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# as tested on the CI via check-warnings.py in reusable-docs.yml.
# Keep lines sorted lexicographically to help avoid merge conflicts.

Doc/c-api/init_config.rst
Doc/c-api/intro.rst
Doc/c-api/stable.rst
Doc/library/ast.rst
Doc/library/asyncio-extending.rst
Doc/library/email.charset.rst
Expand Down
18 changes: 17 additions & 1 deletion Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,22 @@ math
(Contributed by Jeff Epler in :gh:`150534`.)


multiprocessing
---------------

* Add the optional ``buffersize`` parameter to
:meth:`multiprocessing.pool.Pool.imap` and
:meth:`multiprocessing.pool.Pool.imap_unordered` to limit the number of
submitted tasks whose results have not yet been yielded. If the buffer is
full, iteration over the *iterables* pauses until a result is yielded from
the buffer. To fully utilize pool's capacity when using this feature, set
*buffersize* at least to the number of processes in pool (to consume
*iterable* as you go), or even higher (to prefetch the next
``N=buffersize-processes`` arguments).

(Contributed by Oleksandr Baltian in :gh:`136871`.)


os
--

Expand Down Expand Up @@ -606,7 +622,7 @@ module_name


Removed
=======
========

annotationlib
-------------
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions Lib/asyncio/taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,23 @@ async def _aexit(self, et, exc):
self._parent_task.uncancel()
self._parent_task.cancel()
try:
raise BaseExceptionGroup(
'unhandled errors in a TaskGroup',
self._errors,
) from None
# If the *only* error is a GeneratorExit from the body
# of the group, then instead of raising an
# ExceptionGroup we raise GeneratorExit. This ensures
# that async generators that use TaskGroup properly
# swallow the exception on `aclose()` while ensuring
# that no exceptions from subtasks are swallowed.
if (
et is not None
and issubclass(et, GeneratorExit)
and len(self._errors) == 1
):
raise exc
else:
raise BaseExceptionGroup(
'unhandled errors in a TaskGroup',
self._errors,
) from None
finally:
exc = None

Expand Down
53 changes: 6 additions & 47 deletions Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,53 +412,12 @@ def find_library(name):
_get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))


# Listing loaded libraries on other systems will try to use
# functions common to Linux and a few other Unix-like systems.
# See the following for several platforms' documentation of the same API:
# https://man7.org/linux/man-pages/man3/dl_iterate_phdr.3.html
# https://man.freebsd.org/cgi/man.cgi?query=dl_iterate_phdr
# https://man.openbsd.org/dl_iterate_phdr
# https://docs.oracle.com/cd/E88353_01/html/E37843/dl-iterate-phdr-3c.html
if (os.name == "posix" and
sys.platform not in {"darwin", "ios", "tvos", "watchos"}):
import ctypes
if hasattr((_libc := ctypes.CDLL(None)), "dl_iterate_phdr"):

class _dl_phdr_info(ctypes.Structure):
_fields_ = [
("dlpi_addr", ctypes.c_void_p),
("dlpi_name", ctypes.c_char_p),
("dlpi_phdr", ctypes.c_void_p),
("dlpi_phnum", ctypes.c_ushort),
]

_dl_phdr_callback = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.POINTER(_dl_phdr_info),
ctypes.c_size_t,
ctypes.POINTER(ctypes.py_object),
)

@_dl_phdr_callback
def _info_callback(info, _size, data):
libraries = data.contents.value
name = os.fsdecode(info.contents.dlpi_name)
libraries.append(name)
return 0

_dl_iterate_phdr = _libc["dl_iterate_phdr"]
_dl_iterate_phdr.argtypes = [
_dl_phdr_callback,
ctypes.POINTER(ctypes.py_object),
]
_dl_iterate_phdr.restype = ctypes.c_int

def dllist():
"""Return a list of loaded shared libraries in the current process."""
libraries = []
_dl_iterate_phdr(_info_callback,
ctypes.byref(ctypes.py_object(libraries)))
return libraries
# On platforms which provide dl_iterate_phdr(), dllist() is implemented
# in _ctypes.
try:
from _ctypes import dllist
except ImportError:
pass


@dataclass(slots=True, frozen=True)
Expand Down
Loading