RotatingFileHandler "Text file busy" on Windows

I am running django webapp in vagrant (running ubuntu) on a windows machine. The application has the RotatingFileHandler function installed, which for the most part is registered correctly. But in the end, the log file fills up, and at that moment it cannot roll over

Logged from file util.py, line 79 Traceback (most recent call last): File "/usr/lib/python2.7/logging/handlers.py", line 78, in emit self.doRollover() File "/usr/lib/python2.7/logging/handlers.py", line 141, in doRollover os.rename(self.baseFilename, dfn) OSError: [Errno 26] Text file busy 

(many times)

Here is a configuration snippet for RotatingFileHandler:

 'default': { 'level':'DEBUG', 'class':'logging.handlers.RotatingFileHandler', 'filename': 'logs/application.log', 'maxBytes': 1024 * 1024 * 5, # 5 MB 'backupCount': 5, 'formatter':'standard', }, 

The problem is that it is in the public accessible directory, so it is running into Windows file lock problems. If I change it to enter a directory outside the shared directory, it will be turned over.

My question is, is there anything I can do to prevent the error above without moving the exits from the roaming directory?

I would like to keep it there, so that it is more portable for other servers, and so I can view the logs in windows.

+6
source share
1 answer

If you started the Django development server when an error was detected, try

 python manage.py runserver --noreload 

This is because two Django server processes are running by default. One of them is the actual server, and the other is detecting changes in the code and rebooting the server. Therefore, settings.py is imported twice, and therefore, two processes access the log file at the same time.

More details here .

+7
source

All Articles