[Tutor] totally stumped on signal code, wont work in this instance
dave selby
dave6502 at googlemail.com
Fri Feb 6 10:06:58 CET 2009
Hi,
I have been hitting my head on a brick wall on a bit of code that
refuses to work. I have similar code in other scripts that works AOK
I have commented out all functionality except the core problem ...
import sys, threading, time, os.path, urllib, time, signal, ConfigParser, logger
....
def main():
#logger.log('daemon starting ...', 'CRIT')
#read_config()
#thread1 = Thread1_PTZ()
#thread1.setDaemon(True)
#thread1.start()
#thread2 = Thread2_PTZ_Park()
#thread2.setDaemon(True)
#thread2.start()
#thread3 = Thread3_PTZ_Preset()
#thread3.setDaemon(True)
#thread3.start()
while True: # sleep to keep daemons alive :)
time.sleep(60 * 60 * 24)
def signal_hup(signum, frame):
"""
SIGHUP, unlike all other daemons SIGHUP causes this daemon to exit killing
all its daemon threads. This is a workaround. Because 'kmotion_ptzd' is
threaded the only way to get the threads to reliably reload their config
is to kill and restart else they languish in a sleep state for ? secs.
args : discarded
excepts :
return : none
"""
print 'sighup :)'
#logger.log('signal SIGHUP detected, shutting down due to
threading', 'CRIT')
#sys.exit()
...
main()
So main just sits there AOK. I send a sighup to the script with
pkill -SIGHUP -f python.+kmotion_ptzd.py
and I get ...
dave at main-system:~/kmotion2/core$ ./kmotion_ptzd.py
Hangup
dave at main-system:~/kmotion2/core$
OK so I would have expected signal_hup to have intercepted the signal
and printed 'sighup :)'
and also not have exited in this case.
Any ideas, I can solve most of my python probs but this one has me stumped.
Cheers
Dave
--
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
More information about the Tutor
mailing list