Fixes sumulator.py signal_handler logic
Change-Id: I95ee737a6c12572e7b3d27d8ea117c9f2909ef28 Closes-bug: #1576614
This commit is contained in:
parent
bedd400b6a
commit
a98fa8f52f
@ -532,12 +532,17 @@ def write_json_file(filename, output):
|
||||
LOG.info('Stats are written into %s', filename)
|
||||
|
||||
|
||||
class SignalExit(SystemExit):
|
||||
def __init__(self, signo, exccode=1):
|
||||
super(SignalExit, self).__init__(exccode)
|
||||
self.signo = signo
|
||||
|
||||
|
||||
def signal_handler(signum, frame):
|
||||
global IS_RUNNING
|
||||
IS_RUNNING = False
|
||||
LOG.info('Signal %s is caught. Interrupting the execution', signum)
|
||||
for server in SERVERS:
|
||||
server.stop()
|
||||
|
||||
raise SignalExit(signum)
|
||||
|
||||
|
||||
def _setup_logging(is_debug):
|
||||
@ -647,6 +652,7 @@ def main():
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
try:
|
||||
if args.mode == 'rpc-server':
|
||||
target = messaging.Target(topic=args.topic, server=args.server)
|
||||
if args.url.startswith('zmq'):
|
||||
@ -664,14 +670,14 @@ def main():
|
||||
|
||||
elif args.mode == 'batch-notify-server':
|
||||
endpoint = batch_notify_server(transport, args.topic,
|
||||
args.wait_before_answer, args.duration,
|
||||
args.requeue)
|
||||
args.wait_before_answer,
|
||||
args.duration, args.requeue)
|
||||
show_server_stats(endpoint, args.json_filename)
|
||||
|
||||
elif args.mode == 'notify-client':
|
||||
spawn_notify_clients(args.threads, args.topic, transport,
|
||||
args.messages, args.wait_after_msg, args.timeout,
|
||||
args.duration)
|
||||
args.messages, args.wait_after_msg,
|
||||
args.timeout, args.duration)
|
||||
show_client_stats(CLIENTS, args.json_filename)
|
||||
|
||||
elif args.mode == 'rpc-client':
|
||||
@ -688,6 +694,10 @@ def main():
|
||||
if args.exit_wait:
|
||||
LOG.info("Finished. waiting for %d seconds", args.exit_wait)
|
||||
time.sleep(args.exit_wait)
|
||||
except SignalExit as e:
|
||||
LOG.info('Signal %s is caught. Interrupting the execution', e.signo)
|
||||
for server in SERVERS:
|
||||
server.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user