From 1499d73b3e02878850c007fa7298bb62f6c5a9a1 Mon Sep 17 00:00:00 2001 From: Duncan Grisby Date: Tue, 23 Aug 2022 07:28:43 +0100 Subject: =?UTF-8?q?gh-96159:=20Fix=20significant=20performance=20degradati?= =?UTF-8?q?on=20in=20logging.TimedRotat=E2=80=A6=20(GH-96182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/logging/handlers.py | 10 +++++++--- .../next/Library/2022-08-22-18-42-17.gh-issue-96159.3bFU39.rst | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-08-22-18-42-17.gh-issue-96159.3bFU39.rst diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 1c8226c..3f97862 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -348,11 +348,15 @@ class TimedRotatingFileHandler(BaseRotatingHandler): 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 0000000..f64469e --- /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. -- cgit v0.12