FAQ
Hello,

I have a handmade class within a python program which uses the logging
module.
This class has a destructor which is expected to log something into my log
file if a crash occurs.
Well, the destructor works well but during the crash, python has already
closed the log file and the reference to the Logger has been set to None.
So, I can't log anything!

How is it possible to solve this problem?

Thanks.

Search Discussions

  • Vinay Sajip at Oct 27, 2010 at 10:41 pm

    On Oct 27, 3:21?pm, climb65 wrote:
    This class has a destructor which is expected to log something into my log
    file if a crash occurs.
    Well, the destructor works well but during the crash, python has already
    closed the log file and the reference to the Logger has been set to None.
    So, I can't log anything!

    How is it possible to solve this problem?
    Unfortunately, when a process is about to exit (for whatever reason),
    things may not shut down in an order you would like. I'd advise
    wrapping your main program in an try: except: block. If you have a
    main, function, for example:

    import logging, sys

    logger = logging.getLogger(__name__)

    def main():
    #configure logging, say using basicConfig()
    try:
    # here is whatever your main program is doing now
    retcode = 0
    except Exception:
    logger.exception('Exception raised during processing')
    retcode = 1
    sys.exit(retcode)

    if __name__ == '__main__':
    main()

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedOct 27, '10 at 2:21p
activeOct 27, '10 at 10:41p
posts2
users2
websitepython.org

2 users in discussion

Climb65: 1 post Vinay Sajip: 1 post

People

Translate

site design / logo © 2022 Grokbase