You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RotatingFileHandler calls self.format() twice for every record -- first time to determine if rollover should occur, second time to write it to the stream. It is not optimal. Even if the IO time dominates in common cases, the formatting time may be non-trivial -- this is why formatting is delayed.
It is not easy to fix without duplicating the code and introducing a coupling between several handler classes. The simplest way -- check the current file size in shouldRollover(), without adding the size of the new record. This will make the size of backups slightly larger than maxBytes, but this calculation is already inaccurate (see #64336, #69128). This will automatically solve #116263.
Thanks for raising it, the idea makes sense to me, but I guess we might need a wider consensus on this.
Nevertheless, I had a go at the implementation in #116330, which might help with the discussion
Jason-Y-Z
added a commit
to Jason-Y-Z/cpython
that referenced
this issue
Mar 4, 2024
Uh oh!
There was an error while loading. Please reload this page.
RotatingFileHandler
callsself.format()
twice for every record -- first time to determine if rollover should occur, second time to write it to the stream. It is not optimal. Even if the IO time dominates in common cases, the formatting time may be non-trivial -- this is why formatting is delayed.It is not easy to fix without duplicating the code and introducing a coupling between several handler classes. The simplest way -- check the current file size in
shouldRollover()
, without adding the size of the new record. This will make the size of backups slightly larger thanmaxBytes
, but this calculation is already inaccurate (see #64336, #69128). This will automatically solve #116263.Linked PRs
The text was updated successfully, but these errors were encountered: