Multi-process logging error: PermissionError: [WinError 32] Another program is using this file, the process cannot access

tags: python

Multi-process logging error: PermissionError: [WinError 32] Another program is using this file, the process cannot access

Reproduce the problem
2019-12-23 13:28:24,415 - INFO: Ongoing D:\Anaconda_program\hangtian_spider\hangkong/data/EI/01.txt file<RECORD 216>Record reading
--- Logging error ---
Traceback (most recent call last):
  File "D:\Anaconda3\lib\logging\handlers.py", line 72, in emit
    self.doRollover()
  File "D:\Anaconda3\lib\logging\handlers.py", line 173, in doRollover
    self.rotate(self.baseFilename, dfn)
  File "D:\Anaconda3\lib\logging\handlers.py", line 113, in rotate
    os.rename(source, dest)
PermissionError: [WinError 32]  This file is being used by another program and cannot be accessed by the process.: 'D:\\Anaconda_program\\hangtian_spider\\hangkong\\log\\ei_txt_file.log' -> 'D:\\Anaconda_program\\hangtian_spider\\hangkong\\log\\ei_txt_file.log.1'
Call stack:
  File "D:\Anaconda3\lib\threading.py", line 884, in _bootstrap
    self._bootstrap_inner()
  File "D:\Anaconda3\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "D:\Anaconda3\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Anaconda_program\hangtian_spider\hangkong\web\app\data\EI_Data.py", line 228, in get_ei_txt_file
    read_txt(root_dir+file)
  File "D:\Anaconda_program\hangtian_spider\hangkong\web\app\data\EI_Data.py", line 260, in read_txt
    ei_data.add_ei_data(re_dict)
  File "D:\Anaconda_program\hangtian_spider\hangkong\web\app\data\EI_Data.py", line 126, in add_ei_data
    logger.info("The key fields screened in this record are: record_dict.keys(): {}".format(', '.join(record_dict.keys())))
Message: 'The key fields screened in this record are: record_dict.keys(): ei_an, ei_ti, ei_au, ei_af, ei_ca, ei_st, ei_ast, ei_vl, ei_is, ei_isd, ei_py, ei_pg, ei_la, ei_sn, ei_sn, ei_ , ei_ab, ei_nr, ei_mh, ei_ctt, ei_uctt, ei_cfc, ei_di, ei_db, ei_cit'
Arguments: ()
2019-12-23 13:28:24,467 - INFO:  The key fields screened in this record are: record_dict.keys(): ei_an, ei_ti, ei_au, ei_af, ei_ca, ei_st, ei_ast, ei_vl, ei_is, ei_isd, ei_py, ei_pg, ei_la, ei_sn, ei_cn, ei_dt, ei_pu, ei_ab, ei_nr, ei_mh, ei_ctt, ei_uctt, ei_cfc, ei_di, ei_db, ei_cit
--- Logging error ---
Solution
from logging import getLogger, INFO
from concurrent_log_handler import ConcurrentRotatingFileHandler
import os

log = getLogger()
# Use an absolute path to prevent file rotation trouble.
logfile = os.path.abspath("mylogfile.log")
# Rotate log after reaching 512K, keep 5 old copies.
rotateHandler = ConcurrentRotatingFileHandler(logfile, "a", 512*1024, 5)
log.addHandler(rotateHandler)
log.setLevel(INFO)

log.info("Here is a very exciting log message, just for you")
reference

https://github.com/Preston-Landers/concurrent-log-handler
https://blog.csdn.net/chongtong/article/details/80831782

Intelligent Recommendation

Oldwood Take you --- Install the Python Package Permissionerror: [Winerror 32] Another program is using this file, the process is unacceptable.

When installing the python package with xgboost, the following error may occur: Because the terminal under Window is or the GBK encoding is displayed, the PIP source code is also modified. Open C: \ P...

[Winerror 32] Another program is using this file, the process cannot be accessed, # image processing

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...

Kafka in Windows Error: java.nio.file.filesystemXception: Another program is using this file, the process cannot access the process, the process cannot be accessed

Problem Description Kafka deployed in the Windows environment is hung after running for a period of time. View loglogs/server.log Discover the following errors: reason When the consumer's offset log i...

Python Flask Logging Log Reports An error "Another program is using this file, the process cannot be accessed"

Article catalog Problem 2. Code example 3. Reason 4. Solve Problem Python Flask Logging Log Reports An error "Another program is using this file, the process cannot be accessed" 2. Code exam...

An error was reported when starting kafka: java.nio.file.FileSystemException, another program is using this file, and the process cannot access it.

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...

More Recommendation

Java Process: Another program is using this file, the process cannot be accessed

When I recently dealt with strange problems, I made a low -level error, wasted a lot of time, and even watched the C code at the bottom of the JDK. The following test code is run by the Windows enviro...

Solve when deleting a folder or file: another program is using this file and the process cannot access it.

kuaiya\kzippb-This file is being used by another program and the process cannot access it. Problem Description: Usually when deleting a folder or deleting a single file, we often encounter the followi...

Solve the problem of deploying ASP.NET Core to IIS, updating the project "another program is using this file, the process cannot access"

  Problem: The ASP.NET Core project deployed on IIS will cause a process occupation error when updating   Initial solution: 1. Close the application pool 2. Close the website 3. Update the p...

[Error Record] Flutter mixed development error (java.nio.file.filesystemException: xxx / r.jar: Another program is using this file, the process cannot be accessed.)

Article catalog First, error information Second, the solution First, error information FLUTTER Mixed Development Project: In the Android project, embed the flutter page, accidentally run the Flutter p...

VMware reports an error: "Another program has locked a part of the file and the process cannot access it"

Report an error: Another program has locked a part of the file and the process cannot access it Cannot open the disk "E:\Ubuntu\Ubuntu 64-bit .vmdk" or one of the snapshot disks it depends o...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top