Repost: Can't sys.exit() from SIGTERM handler?

Discussion in 'Python' started by Andrew Athan, Jan 6, 2004.

  1. Andrew Athan

    Andrew Athan Guest

    I have a python program (snippet below) which does not want to seem to die
    when I issue a sys.exit() inside the SIGTERM handler. The output below is
    generated as the result of sending several SIGTERM signals to the process,
    as a result of seeing that it had not died.

    I don't think this is relevant, but the application has fork()ed a child
    process (cdparanoia). The only thing I can think of is that somehow, there
    is an exception occuring inside sys.exit(), otherwise why am I not seeing
    the "Did not sys.exit()!?" output? Could it be that exit() is returning but
    that the output fd's are already closed?

    Verrry strange...and therefore I'm sure I'm making a brain dead mistake.

    Thanks in advance,
    A.

    --------------------------------------------------------------------------

    ****SIGTERM*****


    ****SIGTERM*****

    ...
    ****SIGCHILD*****


    Ripper output status code: (4314, 15)
    4320 /root/postprocess /var/music/ripper/8707620b

    ****SIGCHILD*****

    Error JOB_NODISC in job <__main__.JobHandler instance at 0x8204b24>
    4321 /bin/setserial /dev/ttyS0 spd_normal

    ****SIGCHILD*****



    Killing child processes...

    --------------------------------------------------------------------------

    def sigterm(a,b):
    print '\n****SIGTERM*****\n'
    sys.exit()
    print '\nDid not sys.exit()??!!\n'
    killChildren()
    os._exit(1)
    print '\nDid not os._exit()??!!\n'

    def killChildren():
    global childPIDs
    print '\n\nKilling child processes...'
    for pid in childPIDs:
    try:
    print 'Terminating %d'%pid
    os.kill(pid,signal.SIGTERM)
    os.waitpid(pid,0)
    except:
    pass

    def child_exit(a,b):
    #childpid, status = os.wait()
    print '\n****SIGCHILD*****\n'
    pass


    --
    http://mail.python.org/mailman/listinfo/python-list
    Andrew Athan, Jan 6, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Athan
    Replies:
    0
    Views:
    460
    Andrew Athan
    Jan 6, 2004
  2. Andrew Athan
    Replies:
    0
    Views:
    961
    Andrew Athan
    Jan 6, 2004
  3. Jeff Epler
    Replies:
    0
    Views:
    845
    Jeff Epler
    Jan 6, 2004
  4. GinTon

    sys.stderr.write and sys.exit

    GinTon, Nov 23, 2006, in forum: Python
    Replies:
    5
    Views:
    579
    Dennis Lee Bieber
    Nov 24, 2006
  5. Yujo
    Replies:
    2
    Views:
    402
    Gabriel Genellina
    Apr 10, 2007
Loading...

Share This Page