pydnstest/testserver: handle SIGTERM, SIGINT gracefully

parent 569ffd56
...@@ -4,8 +4,10 @@ import argparse ...@@ -4,8 +4,10 @@ import argparse
import itertools import itertools
import logging import logging
import os import os
import signal
import select import select
import socket import socket
import sys
import threading import threading
import time import time
...@@ -256,13 +258,17 @@ def standalone_self_test(): ...@@ -256,13 +258,17 @@ def standalone_self_test():
server.start() server.start()
logging.info("[==========] Mirror server running at %s", server.address()) logging.info("[==========] Mirror server running at %s", server.address())
try:
while True: def exit(signum, frame):
time.sleep(0.5)
except KeyboardInterrupt:
logging.info("[==========] Shutdown.") logging.info("[==========] Shutdown.")
pass server.stop()
server.stop() sys.exit(128 + signum)
signal.signal(signal.SIGINT, exit)
signal.signal(signal.SIGTERM, exit)
while True:
time.sleep(0.5)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment