process: Rename exit_handler() to sigterm_handler()
This commit is contained in:
parent
4691bf5ea6
commit
3a7e7cdde0
@ -27,7 +27,7 @@ def main():
|
|||||||
log.bootstrap_delayed_logging()
|
log.bootstrap_delayed_logging()
|
||||||
logger.info('Starting Mopidy %s', versioning.get_version())
|
logger.info('Starting Mopidy %s', versioning.get_version())
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, process.exit_handler)
|
signal.signal(signal.SIGTERM, process.sigterm_handler)
|
||||||
# Windows does not have signal.SIGUSR1
|
# Windows does not have signal.SIGUSR1
|
||||||
if hasattr(signal, 'SIGUSR1'):
|
if hasattr(signal, 'SIGUSR1'):
|
||||||
signal.signal(signal.SIGUSR1, pykka.debug.log_thread_tracebacks)
|
signal.signal(signal.SIGUSR1, pykka.debug.log_thread_tracebacks)
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import signal
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
@ -12,20 +11,23 @@ from mopidy.compat import thread
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
SIGNALS = dict(
|
|
||||||
(k, v) for v, k in signal.__dict__.items()
|
|
||||||
if v.startswith('SIG') and not v.startswith('SIG_'))
|
|
||||||
|
|
||||||
|
|
||||||
def exit_process():
|
def exit_process():
|
||||||
logger.debug('Interrupting main...')
|
logger.debug('Interrupting main...')
|
||||||
thread.interrupt_main()
|
thread.interrupt_main()
|
||||||
logger.debug('Interrupted main')
|
logger.debug('Interrupted main')
|
||||||
|
|
||||||
|
|
||||||
def exit_handler(signum, frame):
|
def sigterm_handler(signum, frame):
|
||||||
"""A :mod:`signal` handler which will exit the program on signal."""
|
"""A :mod:`signal` handler which will exit the program on signal.
|
||||||
logger.info('Got %s signal', SIGNALS[signum])
|
|
||||||
|
This function is not called when the process' main thread is running a GLib
|
||||||
|
mainloop. In that case, the GLib mainloop must listen for SIGTERM signals
|
||||||
|
and quit itself.
|
||||||
|
|
||||||
|
For Mopidy subcommands that does not run the GLib mainloop, this handler
|
||||||
|
ensures a proper shutdown of the process on SIGTERM.
|
||||||
|
"""
|
||||||
|
logger.info('Got SIGTERM signal. Exiting...')
|
||||||
exit_process()
|
exit_process()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user