简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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