On Aug 1, 11:39 am, Andrea Di Mario <anddima...@gmail.com> wrote:
> Thanks Thomas, it is what i'm looking for.
>
> Regards
>
> --
> Andrea Di Mario

Catch a Kill:

def signal_handler(signal, frame):
        print "Received exit command."
        #server.running = False
        sys.exit()

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

Find and Kill A Process:

import os, signal

process = "websocket.py"

found = False
for line in os.popen("ps ax | grep python"):
        fields = line.split()
        pid = fields[0]
        for field in fields:
                if field.find(process) >= 0:
                        print pid
                        print field
                        os.kill(int(pid), signal.SIGTERM)
                        found = True
                        break
        if found == True:
                break

if found == True:
        print "found and killed web server process."
else:
        print "could not find web server process.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to