Skip to content

Commit

Permalink
[3.10] gh-96159: Fix significant performance degradation in logging.T…
Browse files Browse the repository at this point in the history
…imedRotat… (GH-96182) (GH-96195)

Co-authored-by: Duncan Grisby <duncan-github@grisby.org>
  • Loading branch information
miss-islington and dgrisby committed Aug 23, 2022
1 parent e9ede9d commit 9c34d64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Lib/logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a performance regression in logging TimedRotatingFileHandler. Only check for special files when the rollover time has passed.

0 comments on commit 9c34d64

Please sign in to comment.