I'm writing to log file using the following code:
import logging
from gmplot import gmplot
logging.basicConfig(filename="sample.log", level=logging.INFO)
logging.debug("This is a debug message")
logging.info("Informational message")
logging.error("An error has happened!")
But then it's impossible to delete this file. how can I 'release' this file?
asked May 7, 2018 at 13:17
2 Answers 2
You need to close() your logging:
As explained there: python does not release filehandles to logfile
When your Run class completes, call:
handlers = self.log.handlers[:]
for handler in handlers:
handler.close()
self.log.removeHandler(handler)
answered May 7, 2018 at 13:23
Sign up to request clarification or add additional context in comments.
simply use logging.shutdown(), when you are done with logging.
1 Comment
eric
This is the solution for those here getting
PermissionError
lang-py