Solved: TimedRotatingFileHandler PermissionError: [WinError 32] The process cannot access the file because it is being used by another process
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:
file_handler.suffix = ‘%Y-%m-%d_%H-%M-%S’ and everything started working fine.
root = logging.getLogger()
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]'