Dobry den,

potreboval bych poradit s nasledujicim problemem. Mam napsany jednoduchy forkujici TCP/IP server. Server jako takovy funguje, child procesy se vytvareji i ukoncuji korektne, jediny probleme mam s ukoncenim parent procesu v okamziku, kdy z (napriklad shellu) zavolam signal SIGTERM. Mam osetreno zachyceni signalu a funkci, ktera zajisti, ze se pocka na ukonceni vsech child procesu a pak by se mel ukoncit i parent proces pomoci sys.exit(0). To se ale nestane, parent proces (server) se neukonci, ale skoci do nadrazene while smycky a dale ceka na spojeni a je schopen obsluhovat prichozi spojeni. Relevantni kod:

def cleanup(signal,frame):
   """Clean up the server before shutdown.
   """
   # SIGTERM signal
   if signal == 15:
       print "Received SIGTERM signal, waiting for clients termination"
       while True:
           # In case that there isn't any active clients
           if not clients:
               break
       print "toto se vypise"
       sys.exit(0)
       print "toto se nevypise"

# Nadrazena smycka:
while True:
       # Handle the child temination
       signal.signal(signal.SIGCHLD,reap)

       # Catch the SIGTERM signal
       signal.signal(signal.SIGTERM, cleanup)
       #signal.pause()
       try:
           connection,address = sock.accept()
...

sys.exit(0) se proste neprovede, preskoci se a skoci do nadrazene smycky. Kdyz zkusim pouzit strace, vidim, ze se provedou print prikazy, ale sys.exit(0) uz ne.

Zkousel jsem i terminaci parent procesu pomoci:

os.kill (pid, signal.SIGKILL), kde pid je PID parent procesu, ale bez uspechu.

Nevite co muze byt pricinou problemu?

Lumir

--
Lumír Jasiok
VSB-TU Ostrava - Computer centre
E-mail: [email protected]
http://www.vsb.cz
                                                                                
                                        

_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python

Odpovedet emailem