Python logging.handlers.RotatingFileHandler breaks when inside a loop
I am using logging.handlers.RotatingFileHandler
Django logging for my needs with a max byte size of 1KB.
However, if I do this:
for i in range(1,500):
logger.debug('Hello World')
Then the application crashes and I get a nice Windows 32 error saying that the log file is not available because it is already in use by another process
Traceback (most recent call last):
File "C:\Python27\lib\logging\handlers.py", line 77, in emit
self.doRollover()
File "C:\Python27\lib\logging\handlers.py", line 142, in doRollover
os.rename(self.baseFilename, dfn)
WindowsError: [Error 32] ─ The process cannot access the file because it is being used by another process.
Which kind makes sense, since in the second that the maximum size is reached, the application is still inside the for loop and continues to print.
How can I solve this?
Thanks in advance.
+3
source to share
No one has answered this question yet
Check out similar questions: