Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e310d2b

Browse filesBrowse files
miss-islingtonzhattarhadthedev
authored
[3.13] gh-105623 Fix performance degradation in logging RotatingFileHandler (GH-105887) (GH-121117)
The check for whether the log file is a real file is expensive on NFS filesystems. This commit reorders the rollover condition checking to not do the file type check if the expected file size is less than the rotation threshold. (cherry picked from commit e9b4ec6) Co-authored-by: Craig Robson <craig@zhatt.com> Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
1 parent d5441f6 commit e310d2b
Copy full SHA for e310d2b

File tree

Expand file treeCollapse file tree

2 files changed

+5
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-3
lines changed

‎Lib/logging/handlers.py

Copy file name to clipboardExpand all lines: Lib/logging/handlers.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ def shouldRollover(self, record):
193193
Basically, see if the supplied record would cause the file to exceed
194194
the size limit we have.
195195
"""
196-
# See bpo-45401: Never rollover anything other than regular files
197-
if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
198-
return False
199196
if self.stream is None: # delay was set...
200197
self.stream = self._open()
201198
if self.maxBytes > 0: # are we rolling over?
202199
msg = "%s\n" % self.format(record)
203200
self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
204201
if self.stream.tell() + len(msg) >= self.maxBytes:
202+
# See bpo-45401: Never rollover anything other than regular files
203+
if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
204+
return False
205205
return True
206206
return False
207207

+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix performance degradation in
2+
:class:`logging.handlers.RotatingFileHandler`. Patch by Craig Robson.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.