Re: Bloody signal handling (in embedded Python code)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcin Krol

    Re: Bloody signal handling (in embedded Python code)


    Right, I didn't realize before that Python interpreter has its own
    signal handling routines.

    Now I am able to handle signals in Python code, but it still barfs on exit:

    import time
    import signal
    import sys

    def userBreak(sigNu m, execFrame):
    print "Interrupted,,, "
    sys.exit(sigNum )

    def terminateRun(si gNum, execFrame):
    print "SIGTERM received, terminating."
    sys.exit(sigNum )

    def test():
    time.sleep(1)
    print "success"
    time.sleep(90)

    if __name__ == "__main__":
    signal.signal(s ignal.SIGTERM, terminateRun)
    signal.signal(s ignal.SIGINT, userBreak)
    test()




    The error:

    ../test
    success
    ( pressing Ctrl-C )
    Interrupted,,,
    Exception exceptions.Syst emExit: 2 in 'garbage collection' ignored
    Fatal Python error: unexpected exception during garbage collection
    Aborted


    So the real question is - how to exit cleanly from embedded Python code?


Working...