Ensuring server cleanup on OS signals

atexit won't run registered functions for SIGTERM which we send to the server.
This prevents clean shutdown.

Also making sure that the server logfiles are deleted as well.
This commit is contained in:
Strahinja Val Markovic 2013-10-17 12:21:59 -07:00
parent b4d5b4ffbb
commit 5070835d01
4 changed files with 24 additions and 1 deletions

View File

@ -28,6 +28,7 @@
},
"server_use_vim_stdout": 0,
"server_log_level": "info",
"server_keep_logfiles": 0,
"auto_start_csharp_server": 1,
"auto_stop_csharp_server": 1,
"csharp_server_port": 2000

View File

@ -197,7 +197,7 @@ def _GetCompleterForRequestData( request_data ):
@atexit.register
def _ServerShutdown():
def ServerShutdown():
LOGGER.info( 'Server shutting down' )
if SERVER_STATE:
SERVER_STATE.Shutdown()

View File

@ -25,6 +25,7 @@ import logging
import json
import argparse
import waitress
import signal
from ycm import user_options_store
from ycm import extra_conf_store
@ -34,6 +35,20 @@ def YcmCoreSanityCheck():
raise RuntimeError( 'ycm_core already imported, ycmd has a bug!' )
# We need to manually call ServerShutdown for the signals that turn down ycmd
# because atexit won't handle them.
def SetUpSignalHandler():
def SignalHandler():
import handlers
handlers.ServerShutdown()
for sig in [ signal.SIGTERM,
signal.SIGINT,
signal.SIGHUP,
signal.SIGQUIT ]:
signal.signal( sig, SignalHandler )
def Main():
parser = argparse.ArgumentParser()
parser.add_argument( '--host', type = str, default = 'localhost',
@ -69,6 +84,7 @@ def Main():
# preload has executed.
import handlers
handlers.UpdateUserOptions( options )
SetUpSignalHandler()
waitress.serve( handlers.app,
host = args.host,
port = args.port,

View File

@ -205,6 +205,12 @@ class YouCompleteMe( object ):
self._server_popen.terminate()
os.remove( self._temp_options_filename )
if not self._user_options[ 'server_keep_logfiles' ]:
if self._server_stderr:
os.remove( self._server_stderr )
if self._server_stdout:
os.remove( self._server_stdout )
def OnCurrentIdentifierFinished( self ):
if not self._IsServerAlive():