From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 23 Aug 2022 07:00:40 +0000 (-0700) Subject: [3.10] gh-96159: Fix significant performance degradation in logging.TimedRotat… ... X-Git-Tag: v3.10.7~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c34d644edec7e5d4da78317ad2bbceb246aa039;p=thirdparty%2FPython%2Fcpython.git [3.10] gh-96159: Fix significant performance degradation in logging.TimedRotat… (GH-96182) (GH-96195) Co-authored-by: Duncan Grisby --- diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index b2d1f279225d..32c04202c5aa 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 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.