[Python-checkins] gh-96159: Fix significant performance degradation in logging.TimedRotat… (GH-96182)
vsajip
webhook-mailer at python.org
Tue Aug 23 02:29:04 EDT 2022
https://github.com/python/cpython/commit/1499d73b3e02878850c007fa7298bb62f6c5a9a1
commit: 1499d73b3e02878850c007fa7298bb62f6c5a9a1
branch: main
author: Duncan Grisby <duncan-github at grisby.org>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022-08-23T07:28:43+01:00
summary:
gh-96159: Fix significant performance degradation in logging.TimedRotat… (GH-96182)
files:
A Misc/NEWS.d/next/Library/2022-08-22-18-42-17.gh-issue-96159.3bFU39.rst
M Lib/logging/handlers.py
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 1c8226c18163..3f97862cc37a 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -348,11 +348,15 @@ def shouldRollover(self, record):
record is not used, as we are just comparing times, but it is needed so
the method signatures are the same
"""
- # See bpo-45401: Never rollover anything other than regular files
- if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
- return False
t = int(time.time())
if t >= self.rolloverAt:
+ # See #89564: Never rollover anything other than regular files
+ if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
+ # The file is not a regular file, so do not rollover, but do
+ # set the next rollover time to avoid repeated checks.
+ self.rolloverAt = self.computeRollover(t)
+ return False
+
return True
return False
diff --git a/Misc/NEWS.d/next/Library/2022-08-22-18-42-17.gh-issue-96159.3bFU39.rst b/Misc/NEWS.d/next/Library/2022-08-22-18-42-17.gh-issue-96159.3bFU39.rst
new file mode 100644
index 000000000000..f64469e563f3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-08-22-18-42-17.gh-issue-96159.3bFU39.rst
@@ -0,0 +1 @@
+Fix a performance regression in logging TimedRotatingFileHandler. Only check for special files when the rollover time has passed.
More information about the Python-checkins
mailing list