Commit 3854fc467bad670784d171895f5cdc6babc7842c

Authored by Adhidarma Hadiwinoto
1 parent 961bfbde0c
Exists in master

Trap sigint maupun sigterm

Showing 1 changed file with 5 additions and 2 deletions Side-by-side Diff

... ... @@ -72,8 +72,8 @@ redis_client = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=0)
72 72 def signalHandler(signum, frame):
73 73 global TERMINATING
74 74  
75   - if (signum == signal.SIGINT):
76   - logger.info('SIGINT received, waiting for next loop to terminate. Terminating...')
  75 + if signum == signal.SIGINT or signum == signal.SIGTERM:
  76 + logger.info('Signal ({0}) received, waiting for next loop to terminate. Terminating...'.format(signum))
77 77 TERMINATING = True
78 78  
79 79 def handleSms(sms):
... ... @@ -728,6 +728,9 @@ if __name__ == '__main__':
728 728 pidfile.write(str(getpid()))
729 729 pidfile.close()
730 730  
  731 + # trap CTRL-C
731 732 signal.signal(signal.SIGINT, signalHandler)
  733 + # trap supervisor stop
  734 + signal.signal(signal.SIGTERM, signalHandler)
732 735  
733 736 main()