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:
parent
b4d5b4ffbb
commit
5070835d01
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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,
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user