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
5 changes: 5 additions & 0 deletions Doc/c-api/bytes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ Create, Finish, Discard
If *size* is greater than zero, allocate *size* bytes, and set the
writer size to *size*. The caller is responsible to write *size*
bytes using :c:func:`PyBytesWriter_GetData`.
This function does not overallocate.

On error, set an exception and return ``NULL``.

Expand Down Expand Up @@ -349,6 +350,8 @@ Low-level API

Resize the writer to *size* bytes. It can be used to enlarge or to
shrink the writer.
This function typically overallocates to achieve amortized performance when
resizing multiple times.

Newly allocated bytes are left uninitialized.

Expand All @@ -360,6 +363,8 @@ Low-level API
.. c:function:: int PyBytesWriter_Grow(PyBytesWriter *writer, Py_ssize_t grow)

Resize the writer by adding *grow* bytes to the current writer size.
This function typically overallocates to achieve amortized performance when
resizing multiple times.

Newly allocated bytes are left uninitialized.

Expand Down
3 changes: 2 additions & 1 deletion Doc/deprecations/pending-removal-in-3.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ Pending removal in Python 3.20
- :mod:`tabnanny`
- :mod:`tkinter.font`
- :mod:`tkinter.ttk`
- :mod:`zlib`

(Contributed by Hugo van Kemenade in :gh:`76007`.)
(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
208 changes: 208 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3383,6 +3383,214 @@ features:
Added the :attr:`st_birthtime` member on Windows.


.. function:: statx(path, mask, *, flags=0, dir_fd=None, follow_symlinks=True)

Get the status of a file or file descriptor by performing a :c:func:`!statx`
system call on the given path.

*path* is a :term:`path-like object` or an open file descriptor. *mask* is a
combination of the module-level :const:`STATX_* <STATX_TYPE>` constants
specifying the information to retrieve. *flags* is a combination of the
module-level :const:`AT_STATX_* <AT_STATX_FORCE_SYNC>` constants and/or
:const:`AT_NO_AUTOMOUNT`. Returns a :class:`statx_result` object whose
:attr:`~os.statx_result.stx_mask` attribute specifies the information
actually retrieved (which may differ from *mask*).

This function supports :ref:`specifying a file descriptor <path_fd>`,
:ref:`paths relative to directory descriptors <dir_fd>`, and
:ref:`not following symlinks <follow_symlinks>`.

.. seealso:: The :manpage:`statx(2)` man page.

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next


.. class:: statx_result

Information about a file returned by :func:`os.statx`.

:class:`!statx_result` has all the attributes that :class:`~stat_result` has
on Linux, making it :term:`duck-typing` compatible, but
:class:`!statx_result` is not a subclass of :class:`~stat_result` and cannot
be used as a tuple.

:class:`!statx_result` has the following additional attributes:

.. attribute:: stx_mask

Bitmask of :const:`STATX_* <STATX_TYPE>` constants specifying the
information retrieved, which may differ from what was requested.

.. attribute:: stx_attributes_mask

Bitmask of :const:`STATX_ATTR_* <stat.STATX_ATTR_COMPRESSED>` constants
specifying the attributes bits supported for this file.

.. attribute:: stx_attributes

Bitmask of :const:`STATX_ATTR_* <stat.STATX_ATTR_COMPRESSED>` constants
specifying the attributes of this file.

.. attribute:: stx_dev_major

Major number of the device on which this file resides.

.. attribute:: stx_dev_minor

Minor number of the device on which this file resides.

.. attribute:: stx_rdev_major

Major number of the device this file represents.

.. attribute:: stx_rdev_minor

Minor number of the device this file represents.

.. attribute:: stx_mnt_id

Mount ID.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 5.8.

.. attribute:: stx_dio_mem_align

Direct I/O memory buffer alignment requirement.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.1.

.. attribute:: stx_dio_offset_align

Direct I/O file offset alignment requirement.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.1.

.. attribute:: stx_subvol

Subvolume ID.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.10.

.. attribute:: stx_atomic_write_unit_min

Minimum size for direct I/O with torn-write protection.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.11.

.. attribute:: stx_atomic_write_unit_max

Maximum size for direct I/O with torn-write protection.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.11.

.. attribute:: stx_atomic_write_unit_max_opt

Maximum optimized size for direct I/O with torn-write protection.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.11.

.. attribute:: stx_atomic_write_segments_max

Maximum iovecs for direct I/O with torn-write protection.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.11.

.. attribute:: stx_dio_read_offset_align

Direct I/O file offset alignment requirement for reads.

.. availability:: Linux >= 4.11 with glibc >= 2.28 and build-time kernel
userspace API headers >= 6.14.

.. seealso:: The :manpage:`statx(2)` man page.

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next


.. data:: STATX_TYPE
STATX_MODE
STATX_NLINK
STATX_UID
STATX_GID
STATX_ATIME
STATX_MTIME
STATX_CTIME
STATX_INO
STATX_SIZE
STATX_BLOCKS
STATX_BASIC_STATS
STATX_BTIME
STATX_MNT_ID
STATX_DIOALIGN
STATX_MNT_ID_UNIQUE
STATX_SUBVOL
STATX_WRITE_ATOMIC
STATX_DIO_READ_ALIGN

Bitflags for use in the *mask* parameter to :func:`os.statx`. Flags
including and after :const:`!STATX_MNT_ID` are only available when their
corresponding members in :class:`statx_result` are available.

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next

.. data:: AT_STATX_FORCE_SYNC

A flag for the :func:`os.statx` function. Requests that the kernel return
up-to-date information even when doing so is expensive (for example,
requiring a round trip to the server for a file on a network filesystem).

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next

.. data:: AT_STATX_DONT_SYNC

A flag for the :func:`os.statx` function. Requests that the kernel return
cached information if possible.

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next

.. data:: AT_STATX_SYNC_AS_STAT

A flag for the :func:`os.statx` function. This flag is defined as ``0``, so
it has no effect, but it can be used to explicitly indicate neither
:data:`AT_STATX_FORCE_SYNC` nor :data:`AT_STATX_DONT_SYNC` is being passed.
In the absence of the other two flags, the kernel will generally return
information as fresh as :func:`os.stat` would return.

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next


.. data:: AT_NO_AUTOMOUNT

If the final component of a path is an automount point, operate on the
automount point instead of performing the automount. On Linux,
:func:`os.stat`, :func:`os.fstat` and :func:`os.lstat` always behave this
way.

.. availability:: Linux.

.. versionadded:: next


.. function:: statvfs(path)

Perform a :c:func:`!statvfs` system call on the given path. The return value is
Expand Down
19 changes: 19 additions & 0 deletions Doc/library/stat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,22 @@ constants, but are not an exhaustive list.
IO_REPARSE_TAG_APPEXECLINK

.. versionadded:: 3.8

On Linux, the following file attribute constants are available for use when
testing bits in the :attr:`~os.statx_result.stx_attributes` and
:attr:`~os.statx_result.stx_attributes_mask` members returned by
:func:`os.statx`. See the :manpage:`statx(2)` man page for more detail on the
meaning of these constants.

.. data:: STATX_ATTR_COMPRESSED
STATX_ATTR_IMMUTABLE
STATX_ATTR_APPEND
STATX_ATTR_NODUMP
STATX_ATTR_ENCRYPTED
STATX_ATTR_AUTOMOUNT
STATX_ATTR_MOUNT_ROOT
STATX_ATTR_VERITY
STATX_ATTR_DAX
STATX_ATTR_WRITE_ATOMIC

.. versionadded:: next
4 changes: 2 additions & 2 deletions Doc/reference/lexical_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,8 @@ The parts are separated by a decimal point, ``.``::
2.71828
4.0

Unlike in integer literals, leading zeros are allowed in the numeric parts.
For example, ``077.010`` is legal, and denotes the same number as ``77.10``.
Unlike in integer literals, leading zeros are allowed.
For example, ``077.010`` is legal, and denotes the same number as ``77.01``.

As in integer literals, single underscores may occur between digits to help
readability::
Expand Down
11 changes: 10 additions & 1 deletion Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,14 @@ mmap
(Contributed by Serhiy Storchaka in :gh:`78502`.)


os
--

* Add :func:`os.statx` on Linux kernel versions 4.11 and later with
glibc versions 2.28 and later.
(Contributed by Jeffrey Bosboom in :gh:`83714`.)


os.path
-------

Expand Down Expand Up @@ -828,8 +836,9 @@ New deprecations
- :mod:`tabnanny`
- :mod:`tkinter.font`
- :mod:`tkinter.ttk`
- :mod:`zlib`

(Contributed by Hugo van Kemenade in :gh:`76007`.)
(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)

.. Add deprecations above alphabetically, not here at the end.

Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

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

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(loop)
STRUCT_FOR_ID(manual_reset)
STRUCT_FOR_ID(mapping)
STRUCT_FOR_ID(mask)
STRUCT_FOR_ID(match)
STRUCT_FOR_ID(max_length)
STRUCT_FOR_ID(maxdigits)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

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

4 changes: 4 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

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

2 changes: 2 additions & 0 deletions Include/refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ PyAPI_FUNC(Py_ssize_t) Py_REFCNT(PyObject *ob);
}
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
# define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST(ob))
#else
# define Py_REFCNT(ob) _Py_REFCNT(ob)
#endif
#endif

Expand Down
6 changes: 6 additions & 0 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def _add(str, fn):
_add("HAVE_UNLINKAT", "unlink")
_add("HAVE_UNLINKAT", "rmdir")
_add("HAVE_UTIMENSAT", "utime")
if _exists("statx"):
_set.add(statx)
supports_dir_fd = _set

_set = set()
Expand All @@ -157,6 +159,8 @@ def _add(str, fn):
_add("HAVE_FPATHCONF", "pathconf")
if _exists("statvfs") and _exists("fstatvfs"): # mac os x10.3
_add("HAVE_FSTATVFS", "statvfs")
if _exists("statx"):
_set.add(statx)
supports_fd = _set

_set = set()
Expand Down Expand Up @@ -195,6 +199,8 @@ def _add(str, fn):
_add("HAVE_FSTATAT", "stat")
_add("HAVE_UTIMENSAT", "utime")
_add("MS_WINDOWS", "stat")
if _exists("statx"):
_set.add(statx)
supports_follow_symlinks = _set

del _set
Expand Down
11 changes: 8 additions & 3 deletions Lib/profiling/sampling/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,14 @@ def sample(

if output_format == "pstats" and not filename:
stats = pstats.SampledStats(collector).strip_dirs()
print_sampled_stats(
stats, sort, limit, show_summary, sample_interval_usec
)
if not stats.stats:
print("No samples were collected.")
if mode == PROFILING_MODE_CPU:
print("This can happen in CPU mode when all threads are idle.")
else:
print_sampled_stats(
stats, sort, limit, show_summary, sample_interval_usec
)
else:
collector.export(filename)

Expand Down
Loading
Loading