diff --git a/tremolo/tremolo.py b/tremolo/tremolo.py index 3f959c5..6f50abc 100644 --- a/tremolo/tremolo.py +++ b/tremolo/tremolo.py @@ -452,7 +452,7 @@ def _worker(self, host, port, **kwargs): signal.signal(signal.SIGTERM, lambda signum, frame: task.cancel()) try: - self.loop.run_forever() + self.loop.run_forever() # until loop.stop() is called finally: try: if not task.cancelled(): @@ -697,7 +697,9 @@ def run(self, host=None, port=0, reuse_port=True, worker_num=1, **kwargs): print('-' * terminal_width) print('%s main (pid %d) is running ' % (server_name, os.getpid())) - self.manager.wait(timeout=kwargs['shutdown_timeout']) - for sock in socks.values(): - self.close_sock(sock) + try: + self.manager.wait(timeout=kwargs['shutdown_timeout']) + finally: + for sock in socks.values(): + self.close_sock(sock)