Python Flask Logging Log Reports An error "Another program is using this file, the process cannot be accessed"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: craftsman
import os
import datetime
import decimal
import logging
from logging.handlers import TimedRotatingFileHandler
import redis
import json
from flask import Flask, request, make_response, current_app, g
from flask import render_template
from flask import jsonify
from flask import send_from_directory
from flask_sqlalchemy import SQLAlchemy
import flask.json
from config import sql_db_config
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
LOG_PATH = os.path.join(BASE_DIR, 'logs')
app = Flask(__name__)
# Configure log information
# Set the log level of the log
logging.basicConfig(level=logging.INFO)
# Create a logging device, specify the path saved by the log, the maximum size of each log file, saved the number of log files
file_log_handler = TimedRotatingFileHandler(filename=os.path.join(LOG_PATH, 'info.log'),
when='midnight', backupCount=31, interval=1, encoding='utf-8')
# Create a logging format log level Enter the file name row log information for log information
formatter = logging.Formatter('[%(levelname)s %(filename)s:%(lineno)d]: %(message)s')
# Set the logging format for the log recorder you just created
file_log_handler.setFormatter(formatter)
# Add a day recorder for the global log tool object (used by Flask App)
logging.getLogger().addHandler(file_log_handler)
app.logger.addHandler(file_log_handler)
When using RotatingFileHandler or TimerotatingFileHandler in Flask, this is the case when the log file is backed up, and it is written to the same log file, and write a conflict.
pip install concurrent-log-handler
After installation, the code above will not report any more, and the log will automatically back up.

appendix:
For details, please refer to: https://github.com/preston-landers/concurrent-log-handler
Today, the website deployed with IIS cannot be started locally. The default port of https is 443. In order to avoid the port starting with 4 on the local computer, I tried to use port 555, and the pro...
Environment: kafka_2.11-1.1.0, win7_64, java8 Phenomenon: automatically stops after 30 seconds of startup, reported [another program is using this file, the process cannot be accessed] It can be seen ...
Regarding the idea when compiling idea: Another program is using this file and the process cannot be accessed. Problem repair record First report the original text: Error:Maven Resources Compiler: Fai...
When making image processing, I used three modules OS, PIL, CV2. I encountered a bug who plagued one morning, I investigated several resource monitor ~~~, bug as follows: Description of Requirement: 1...
Question: After posting the file to the remote interface, open the excel file for classification and processing, and the excel file cannot be deleted. Reason: Requests.post is not closed. Solution: Ma...
The virtual machine suddenly reported an error after a certain system as follows: Seeing this interface, although I don’t know the specific reason for the error, I can roughly guess the reason f...
Use Exifread to find a picture date, rename the file, and another program is using this file, the process is unacceptable. Error prompt appears: Traceback (most recent call last): File "C:...
Paste the error message first Cause Analysis: Failed to clean up the consumer_offset record in the D:\tmp\kafka-logs directory consumer_offset is the topic that Kafka automatically saves the offset, a...
I can't shut down the virtual machine, so I restarted the computer directly, and it turned out like this after restarting. reason: .lck file is a disk lock file of VMWare software. Since the virtual d...
Game development platform: Unity Programming platform: Visual Studio 2017 or above Languages spoken: C# Problem description Moving Logs/AssetImportWorker 1.log to Logs/AssetImportWorker 1-pre...