Search code examples
pythonlinuxloggingexceptionioerror

Catch "Out of memory error" from python logging


I am running a python scripts which downloads data and processes it. I am also logging some key information. My question is that how will I catch an out of memory exception if thrown by logging, as logging writes to a file. Do I have to put all logging calls within a try and except?


Solution

  • You can create your own logging class that derives from logging but calls log within a try: ... expect: clause.