Skip to content

Commit 1499d73

Browse files
authored
gh-96159: Fix significant performance degradation in logging.TimedRotat… (GH-96182)
1 parent 129998b commit 1499d73

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Lib/logging/handlers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,15 @@ def shouldRollover(self, record):
348348
record is not used, as we are just comparing times, but it is needed so
349349
the method signatures are the same
350350
"""
351-
# See bpo-45401: Never rollover anything other than regular files
352-
if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
353-
return False
354351
t = int(time.time())
355352
if t >= self.rolloverAt:
353+
# See #89564: Never rollover anything other than regular files
354+
if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
355+
# The file is not a regular file, so do not rollover, but do
356+
# set the next rollover time to avoid repeated checks.
357+
self.rolloverAt = self.computeRollover(t)
358+
return False
359+
356360
return True
357361
return False
358362

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a performance regression in logging TimedRotatingFileHandler. Only check for special files when the rollover time has passed.

0 commit comments

Comments
 (0)