Exit a Python process not kill it (via ssh) -


i starting script locally via:

sudo python run.py remote 

this script happens open subprocess (if matters)

webcam = subprocess.popen('avconv -f video4linux2 -s 320x240 -r 20 -i /dev/video0 -an -metadata title="officebot" -f flv rtmp://6f7528a4.fme.bambuser.com/b-fme/xxx', shell = true) 

i want know how terminate script when ssh in.

i understand can do:

sudo pkill -f "python run.py remote" 

or use:

ps -f -c python 

to find process id , kill way.

however none of these gracefully kill process, want able trigger equilivent of ctrl/cmd c register exit command (i lots of things on shutdown aren't triggered when process killed).

thank you!

you should use "signals" it:

http://docs.python.org/2/library/signal.html

example:

import signal, os  def handler(signum, frame):     print 'signal handler called signal', signum  signal.signal(signal.sigint, handler) #do stuff 

then in terminal:

kill -int $pid 

or ctrl+c if script active in current shell

http://en.wikipedia.org/wiki/unix_signal

also might useful:

how create daemon in python?


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -