Solved: TimedRotatingFileHandler PermissionError: [WinError 32] The process cannot access the file because it is being used by another process
![Solved: TimedRotatingFileHandler PermissionError: [WinError 32] The process cannot access the file because it is being used by another process](https://www.gotals.com/wp-content/uploads/2019/12/Python-Programming-720x340.png)
While using TimedRotatingFileHandler logging in Python flask application, when my app try to create a backup after a defined time that time it’s show error “TimedRotatingFileHandler PermissionError: [WinError 32] The process cannot access the file because it is being used by another process”
So if you are getting the similar error please follow the below steps.
you just need to look at your “suffix” configuration part of TimedRotatingFileHandler , you may try to use the variable which is not supported by TimedRotatingFileHandler in your “suffix“.
to fixed this issue i made the below changes:
{Read:- How To Run Python 3 Flask App with Gunicorn - Step by Step Guide }
file_handler.suffix = ‘%Y-%m-%d_%H-%M-%S’ and everything started working fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root = logging.getLogger() root.setLevel(logging.INFO) file_name = 'app.log' file_handler = logging.handlers.TimedRotatingFileHandler( LOGS_PATH + '/%s' % file_name, when='W0', interval=1, backupCount=2, encoding='UTF-8' ) file_handler.suffix = '%Y-%m-%d_%H-%M-%S' formatter = RequestFormatter( '[%(asctime)s] %(remote_addr)s requested %(url)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]' ) file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) root.addHandler(file_handler) |