When using RotatingFileHandler for django logging, the following error occurs:
Traceback (most recent call last): File "C:\Python27\lib\logging\handlers.py", line 78, in emit self.doRollover() File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover os.rename(self.baseFilename, dfn) WindowsError: [Error 32] The process cannot access the file because it is being used by another process
If you use settings.py to specify the logging configuration, and you are running django development server, run it with “–noreload” option may help, i.e.
python manage.py runserver --noreload
The reason is that by default, two processes of Django servers are running. One is the actual server, while the other is to detect changes in the code and reload the server. Therefore, settings.py is imported twice, and consequently the two processes are accessing the log file at the same time.
Warning: the following is irrelavent.
I found out this simple solution through hours of googling.
At one point, I thought this was because file handles are inherited by child processes in Python, and I even tried to overwrite the
Finally, this answer enlightened me. I never knew settings.py was imported twice by Django development server!
Post the answer to your own question if you find out the solution. Someone may thank you one day, denvercoder9.
The most obvious solution is most easily neglected.