mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-23 15:08:00 +00:00
only set signal handler on server start and stop
This commit is contained in:
parent
4979d598f1
commit
be556163c9
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue