From 7a31eb61502b5ba4bd0818b06ac39501320d0696 Mon Sep 17 00:00:00 2001 From: nggit <12218311+nggit@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:11:37 +0700 Subject: [PATCH] optimize --- tremolo/tremolo.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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)