From be556163c96a648339c35573091327e572cc16c0 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Tue, 20 Dec 2022 06:08:17 -0500 Subject: [PATCH] only set signal handler on server start and stop --- relay/application.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/relay/application.py b/relay/application.py index 16325fd..057454b 100644 --- a/relay/application.py +++ b/relay/application.py @@ -40,7 +40,6 @@ class Application(web.Application): self['last_worker'] = 0 self.database.create() - self.set_signal_handler() with self.database.session as s: set_level(s.get_config('log_level')) @@ -98,10 +97,10 @@ class Application(web.Application): self['last_worker'] = 0 - def set_signal_handler(self): + def set_signal_handler(self, enable=True): for sig in {'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGTERM'}: try: - signal.signal(getattr(signal, sig), self.stop) + signal.signal(getattr(signal, sig), self.stop if enable else signal.SIG_DFL) # some signals don't exist in windows, so skip them except AttributeError: @@ -129,6 +128,7 @@ class Application(web.Application): async def handle_run(self): + self.set_signal_handler(True) self['running'] = True with self.database.session as s: @@ -161,6 +161,7 @@ class Application(web.Application): self['starttime'] = None self['running'] = False self['workers'].clear() + self.set_signal_handler(False) class PushWorker(threading.Thread):