]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-96159: Fix significant performance degradation in logging.TimedRotat… ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 23 Aug 2022 07:01:10 +0000 (00:01 -0700)
committerGitHub <noreply@github.com>
Tue, 23 Aug 2022 07:01:10 +0000 (08:01 +0100)
Co-authored-by: Duncan Grisby <duncan-github@grisby.org>
Lib/logging/handlers.py
Misc/NEWS.d/next/Library/2022-08-22-18-42-17.gh-issue-96159.3bFU39.rst [new file with mode: 0644]

index 78b756019dc8391ecf7c3bdfeca106f0d261ed4c..2bcab657ba4e4f709b97058df17aa8fbd528d186 100644 (file)
@@ -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 (file)
index 0000000..f64469e
--- /dev/null
@@ -0,0 +1 @@
+Fix a performance regression in logging TimedRotatingFileHandler. Only check for special files when the rollover time has passed.