Use shutdown request to stop server
Use shutdown request to stop ycmd server in a portable way.
This commit is contained in:
parent
c1047bee9a
commit
630b85ad01
54
python/ycm/client/shutdown_request.py
Normal file
54
python/ycm/client/shutdown_request.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright (C) 2016 YouCompleteMe contributors
|
||||
#
|
||||
# This file is part of YouCompleteMe.
|
||||
#
|
||||
# YouCompleteMe is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# YouCompleteMe is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import * # noqa
|
||||
|
||||
from requests.exceptions import ReadTimeout
|
||||
|
||||
from ycm.client.base_request import BaseRequest
|
||||
|
||||
TIMEOUT_SECONDS = 0.1
|
||||
|
||||
|
||||
class ShutdownRequest( BaseRequest ):
|
||||
def __init__( self ):
|
||||
super( BaseRequest, self ).__init__()
|
||||
|
||||
|
||||
def Start( self ):
|
||||
try:
|
||||
self.PostDataToHandler( {},
|
||||
'shutdown',
|
||||
TIMEOUT_SECONDS )
|
||||
except ReadTimeout:
|
||||
pass
|
||||
|
||||
|
||||
def Response( self ):
|
||||
return self._response
|
||||
|
||||
|
||||
def SendShutdownRequest():
|
||||
request = ShutdownRequest()
|
||||
# This is a blocking call.
|
||||
request.Start()
|
@ -49,6 +49,7 @@ from ycm.client.completion_request import ( CompletionRequest,
|
||||
from ycm.client.omni_completion_request import OmniCompletionRequest
|
||||
from ycm.client.event_notification import ( SendEventNotificationAsync,
|
||||
EventNotification )
|
||||
from ycm.client.shutdown_request import SendShutdownRequest
|
||||
|
||||
try:
|
||||
from UltiSnips import UltiSnips_Manager
|
||||
@ -107,6 +108,7 @@ DIAGNOSTIC_UI_FILETYPES = set( [ 'cpp', 'cs', 'c', 'objc', 'objcpp' ] )
|
||||
|
||||
class YouCompleteMe( object ):
|
||||
def __init__( self, user_options ):
|
||||
self._available_completers = {}
|
||||
self._user_options = user_options
|
||||
self._user_notified_about_crash = False
|
||||
self._diag_interface = DiagnosticInterface( user_options )
|
||||
@ -127,6 +129,7 @@ class YouCompleteMe( object ):
|
||||
|
||||
def _SetupServer( self ):
|
||||
self._available_completers = {}
|
||||
self._user_notified_about_crash = False
|
||||
server_port = utils.GetUnusedLocalhostPort()
|
||||
# The temp options file is deleted by ycmd during startup
|
||||
with NamedTemporaryFile( delete = False, mode = 'w+' ) as options_file:
|
||||
@ -143,7 +146,7 @@ class YouCompleteMe( object ):
|
||||
'--options_file={0}'.format( options_file.name ),
|
||||
'--log={0}'.format( self._user_options[ 'server_log_level' ] ),
|
||||
'--idle_suicide_seconds={0}'.format(
|
||||
SERVER_IDLE_SUICIDE_SECONDS )]
|
||||
SERVER_IDLE_SUICIDE_SECONDS ) ]
|
||||
|
||||
filename_format = os.path.join( utils.PathToCreatedTempDir(),
|
||||
'server_{port}_{std}.log' )
|
||||
@ -206,16 +209,15 @@ class YouCompleteMe( object ):
|
||||
return self._server_popen.pid
|
||||
|
||||
|
||||
def _ServerCleanup( self ):
|
||||
def _ShutdownServer( self ):
|
||||
if self.IsServerAlive():
|
||||
self._server_popen.terminate()
|
||||
SendShutdownRequest()
|
||||
|
||||
|
||||
def RestartServer( self ):
|
||||
self._CloseLogs()
|
||||
vimsupport.PostVimMessage( 'Restarting ycmd server...' )
|
||||
self._user_notified_about_crash = False
|
||||
self._ServerCleanup()
|
||||
self._ShutdownServer()
|
||||
self._SetupServer()
|
||||
|
||||
|
||||
@ -332,7 +334,7 @@ class YouCompleteMe( object ):
|
||||
|
||||
|
||||
def OnVimLeave( self ):
|
||||
self._ServerCleanup()
|
||||
self._ShutdownServer()
|
||||
|
||||
|
||||
def OnCurrentIdentifierFinished( self ):
|
||||
|
Loading…
Reference in New Issue
Block a user