简体   繁体   English

python日志记录不会释放文件

[英]python logging does not release file

I have been using logging and notice that after first compile, the output file for logging hangs, and I cannot remove it till I close IDLE. 我一直在使用日志记录,并注意到在第一次编译后,用于日志记录的输出文件将挂起,直到关闭IDLE,我才能将其删除。

I believe that I should "close" logging before the compilation finish, but don't know how to do that with the way that I am using logging: 我相信我应该在编译完成之前“关闭”日志记录,但是不知道该如何使用日志记录方式:

LOGFILE = os.path.join(backup_folder,'test.log')
logging.basicConfig(filename=LOGFILE,level=logging.DEBUG,format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
logging.debug('test')

So seems that I have found a way by adding in the end: 看来我终于找到了一种方法:

logging.shutdown()

This instruction close all handlers that was openned. 该指令关闭所有打开的处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM