◐ Shell
clean mode source ↗

gh-84649: Use statx() in TimedRotatingFileHandler if available by serhiy-storchaka · Pull Request #150968 · python/cpython

serhiy-storchaka

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vstinner, could you please look at this? Do I use statx() like it is supposed to be used?

@unittest.skipUnless(hasattr(os.stat_result, 'st_birthtime') or
support.has_st_birthtime or hasattr(os, 'statx'),
"st_birthtime and statx() not available or supported by Python on this OS")
# @support.requires_resource('walltime')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary, to run tests once on CI.

This allows to support rotation based on the file birth time on Linux.

vstinner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The code using os.statx() is correct. Don't forget to uncomment # @support.requires_resource('walltime').

# Use stx_btime whenever it is available or use stx_ctime
# instead otherwise
creation_time = statx_result.stx_btime
if creation_time is None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, stx_btime can be None. For example, on a tmpfs filesystem, on Linux 5.17 and older: #83714 (comment).

@read-the-docs-community