Python script under daemontools does not get signal 15
"Raj [mail list]" <[email protected]> Mon, 3 Feb 2014 10:49:28 +0530
| Newsgroups | gmane.comp.djb.syslog |
|---|---|
| Message-ID | <CAE56t+XA=YYVWGa5N1NGtO2cxcLG=JSmrcm4cVLcLA7hcc7P8g@mail.gmail.com> |
I have a python script which I want to run as a daemon under
daemontools. My program catches SIGINT and SIGALRM and when the
signals are received program exits.
When the program is run from command line and kill -1 <pid> and kill
-15 <pid> is signaled, the signal handler is run, which causes program
to exit, and corresponding logs are printed.
But when the program is run under daemontools, and svc -d
/service/myrogram is executed, the program neither exits nor logs are
printed.
I am using following run script to run the program under daemontools
#!/bin/sh
exec 2>&1
/usr/bin/python /home/test/sigtest.py
I am wondering why kill -15 <pid> works while svc -d /service/myrogram
does not seems to deliver the signal to the python program.
The python script I am working with is:
from pyudev import Context, Monitor, MonitorObserver
import signal, sys, time
def print_device_event(device):
print ('New event - {0.action}: {0.device_path}'.format(device))
if __name__ == '__main__':
context = Context()
monitor = Monitor.from_netlink(context)
observer = MonitorObserver(monitor, callback=print_device_event,
name='monitor-observer')
print ("Processing started")
observer.start()
def handler(signum, frame):
print("Received Signal: %d"%signum)
observer.send_stop()
print("Exiting.")
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGHUP, handler)
try:
while observer.is_alive():
observer.join(timeout=1.0)
except (KeyboardInterrupt, SystemExit):
print("Caught KeyboardInterrupt, exiting")
observer.send_stop()
Any help is much appreciated
Thanks and Regards,
Raj