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

A

Andrew Athan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top