Removing the server_idle_suicide_seconds option

This option existed so that the user can tweak it if they found the default idle
timeout too short, for instance if they leave their machine on over the weekend.

This use case is now covered by the new YcmdKeepalive system that pings ycmd
every 10 minutes as long as Vim is running. This prevents ycmd shutting down if
one leaves their Vim instance alone for a long time.

Thus the old option is useless now; ycmd now shuts down after 3 hours of
inactivity, which should only ever happen when its corresponding Vim instance
has shut down abnormally.
This commit is contained in:
Strahinja Val Markovic 2013-11-20 12:33:57 -08:00
parent 8d42f72517
commit cf6211055e
5 changed files with 95 additions and 38 deletions

View File

@ -938,29 +938,6 @@ Default: `info`
let g:ycm_server_log_level = 'info'
### The `g:ycm_server_idle_suicide_seconds` option
This option sets the number of seconds of `ycmd` server idleness (no requests
received) after which the server stops itself. NOTE: the YCM Vim client sends a
shutdown request to the server when Vim is shutting down.
If your Vim crashes for instance, `ycmd` never gets the shutdown command and
becomes a zombie process. This option prevents such zombies from sticking around
forever.
The default option is `43200` seconds which is 12 hours. The reason for the
interval being this long is to prevent the server from shutting down if you
leave your computer (and Vim) turned on during the night.
A setting of `0` turns off the timer.
The server "heartbeat" that checks whether this interval has passed occurs every
10 minutes.
Default: `43200`
let g:ycm_server_idle_suicide_seconds = 43200
### The `g:ycm_csharp_server_port` option
The port number (on `localhost`) on which the OmniSharp server should be

View File

@ -110,9 +110,6 @@ let g:ycm_server_log_level =
let g:ycm_server_keep_logfiles =
\ get( g:, 'ycm_server_keep_logfiles', 0 )
let g:ycm_server_idle_suicide_seconds =
\ get( g:, 'ycm_server_idle_suicide_seconds', 86400 )
let g:ycm_extra_conf_vim_data =
\ get( g:, 'ycm_extra_conf_vim_data', [] )

View File

@ -48,6 +48,16 @@ class BaseRequest( object ):
def Response( self ):
return {}
# This method blocks
# |timeout| is num seconds to tolerate no response from server before giving
# up; see Requests docs for details (we just pass the param along).
@staticmethod
def GetDataFromHandler( handler, timeout = DEFAULT_TIMEOUT_SEC ):
return JsonFromFuture( BaseRequest._TalkToHandlerAsync( '',
handler,
'GET',
timeout ) )
# This is the blocking version of the method. See below for async.
# |timeout| is num seconds to tolerate no response from server before giving
@ -64,22 +74,43 @@ class BaseRequest( object ):
# up; see Requests docs for details (we just pass the param along).
@staticmethod
def PostDataToHandlerAsync( data, handler, timeout = DEFAULT_TIMEOUT_SEC ):
def PostData( data, handler, timeout ):
return BaseRequest.session.post( _BuildUri( handler ),
data = json.dumps( data ),
headers = HEADERS,
timeout = timeout )
return BaseRequest._TalkToHandlerAsync( data, handler, 'POST', timeout )
# This returns a future! Use JsonFromFuture to get the value.
# |method| is either 'POST' or 'GET'.
# |timeout| is num seconds to tolerate no response from server before giving
# up; see Requests docs for details (we just pass the param along).
@staticmethod
def _TalkToHandlerAsync( data,
handler,
method,
timeout = DEFAULT_TIMEOUT_SEC ):
def SendRequest( data, handler, method, timeout ):
if method == 'POST':
return BaseRequest.session.post( _BuildUri( handler ),
data = json.dumps( data ),
headers = HEADERS,
timeout = timeout )
if method == 'GET':
return BaseRequest.session.get( _BuildUri( handler ),
headers = HEADERS,
timeout = timeout )
@retries( 5, delay = 0.5, backoff = 1.5 )
def DelayedPostData( data, handler ):
return requests.post( _BuildUri( handler ),
data = json.dumps( data ),
headers = HEADERS )
def DelayedSendRequest( data, handler, method ):
if method == 'POST':
return requests.post( _BuildUri( handler ),
data = json.dumps( data ),
headers = HEADERS )
if method == 'GET':
return requests.get( _BuildUri( handler ),
headers = HEADERS )
if not _CheckServerIsHealthyWithCache():
return EXECUTOR.submit( DelayedPostData, data, handler )
return EXECUTOR.submit( DelayedSendRequest, data, handler, method )
return PostData( data, handler, timeout )
return SendRequest( data, handler, method, timeout )
session = FuturesSession( executor = EXECUTOR )

View File

@ -0,0 +1,48 @@
#!/usr/bin/env python
#
# Copyright (C) 2013 Strahinja Val Markovic <val@markovic.io>
#
# 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/>.
import time
from threading import Thread
from ycm.client.base_request import BaseRequest
# This class can be used to keep the ycmd server alive for the duration of the
# life of the client. By default, ycmd shuts down if it doesn't see a request in
# a while.
class YcmdKeepalive( object ):
def __init__( self, ping_interval_seconds = 60 * 10 ):
self._keepalive_thread = Thread( target = self._ThreadMain )
self._keepalive_thread.daemon = True
self._ping_interval_seconds = ping_interval_seconds
def Start( self ):
self._keepalive_thread.start()
def _ThreadMain( self ):
while True:
time.sleep( self._ping_interval_seconds )
# We don't care if there's an intermittent problem in contacting the
# server; it's fine to just skip this ping.
try:
BaseRequest.GetDataFromHandler( 'healthy' )
except:
pass

View File

@ -27,6 +27,7 @@ from ycm import utils
from ycm.completers.all.omni_completer import OmniCompleter
from ycm.completers.general import syntax_parse
from ycm.completers.completer_utils import FiletypeCompleterExistsForFiletype
from ycm.client.ycmd_keepalive import YcmdKeepalive
from ycm.client.base_request import BaseRequest, BuildRequestData
from ycm.client.command_request import SendCommandRequest
from ycm.client.completion_request import CompletionRequest
@ -57,6 +58,7 @@ SERVER_CRASH_MESSAGE_STDERR_FILE = (
SERVER_CRASH_MESSAGE_SAME_STDERR = (
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). '
' check console output for logs!' )
SERVER_IDLE_SUICIDE_SECONDS = 10800 # 3 hours
class YouCompleteMe( object ):
@ -70,7 +72,9 @@ class YouCompleteMe( object ):
self._server_popen = None
self._filetypes_with_keywords_loaded = set()
self._temp_options_filename = None
self._ycmd_keepalive = YcmdKeepalive()
self._SetupServer()
self._ycmd_keepalive.Start()
def _SetupServer( self ):
@ -84,7 +88,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(
self._user_options[ 'server_idle_suicide_seconds' ] ) ]
SERVER_IDLE_SUICIDE_SECONDS ) ]
BaseRequest.server_location = 'http://localhost:' + str( server_port )