Skip to content

gh-84649: Use statx() in TimedRotatingFileHandler if available - #150968

Merged
serhiy-storchaka merged 3 commits into
python:mainfrom
serhiy-storchaka:TimedRotatingFileHandler-statx
Jun 6, 2026
Merged

gh-84649: Use statx() in TimedRotatingFileHandler if available#150968
serhiy-storchaka merged 3 commits into
python:mainfrom
serhiy-storchaka:TimedRotatingFileHandler-statx

Conversation

@serhiy-storchaka

@serhiy-storchakaserhiy-storchaka commented Jun 5, 2026

Copy link
Copy Markdown
Member

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

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
MemberAuthor

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?

Comment threadLib/test/test_logging.py Outdated
@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')

Copy link
Copy Markdown
MemberAuthor

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.
@serhiy-storchaka
serhiy-storchakaforce-pushed the TimedRotatingFileHandler-statx branch from e584956 to e1c910eCompareJune 5, 2026 13:11

@vstinnervstinner left a comment

Copy link
Copy Markdown
Member

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:

Copy link
Copy Markdown
Member

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

read-the-docs-communityBot commented Jun 5, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33010529 | 📁 Comparing 643c819 against main (9f225e2)

🔍 Preview build

3 files changed
±library/logging.handlers.html
±whatsnew/3.16.html
±whatsnew/changelog.html

@serhiy-storchaka
serhiy-storchaka merged commit b18b6a4 into python:mainJun 6, 2026
52 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the TimedRotatingFileHandler-statx branch July 1, 2026 16:47
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@vstinner