diff --git a/python/ycm/client/base_request.py b/python/ycm/client/base_request.py index 48da08b9..3efd803e 100644 --- a/python/ycm/client/base_request.py +++ b/python/ycm/client/base_request.py @@ -48,19 +48,25 @@ class BaseRequest( object ): # This is the blocking version of the method. See below for async. + # |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 PostDataToHandler( data, handler ): + def PostDataToHandler( data, handler, timeout = None ): return JsonFromFuture( BaseRequest.PostDataToHandlerAsync( data, - handler ) ) + handler, + timeout ) ) # This returns a future! Use JsonFromFuture to get the value. + # |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 PostDataToHandlerAsync( data, handler ): - def PostData( data, handler ): + def PostDataToHandlerAsync( data, handler, timeout = None ): + def PostData( data, handler, timeout ): return BaseRequest.session.post( _BuildUri( handler ), - data = json.dumps( data ), - headers = HEADERS ) + data = json.dumps( data ), + headers = HEADERS, + timeout = timeout ) @retries( 3, delay = 0.5 ) def DelayedPostData( data, handler ): @@ -71,7 +77,7 @@ class BaseRequest( object ): if not _CheckServerIsHealthyWithCache(): return EXECUTOR.submit( DelayedPostData, data, handler ) - return PostData( data, handler ) + return PostData( data, handler, timeout ) session = FuturesSession( executor = EXECUTOR ) diff --git a/python/ycm/client/completion_request.py b/python/ycm/client/completion_request.py index e8af21a7..bb0001c2 100644 --- a/python/ycm/client/completion_request.py +++ b/python/ycm/client/completion_request.py @@ -20,8 +20,9 @@ from ycm import base from ycm import vimsupport from ycm.client.base_request import ( BaseRequest, BuildRequestData, - JsonFromFuture ) + JsonFromFuture ) +TIMEOUT_SECONDS = 0.5 class CompletionRequest( BaseRequest ): def __init__( self, force_semantic = False ): @@ -42,7 +43,8 @@ class CompletionRequest( BaseRequest ): def Start( self, query ): self.request_data[ 'query' ] = query self._response_future = self.PostDataToHandlerAsync( self.request_data, - 'completions' ) + 'completions', + TIMEOUT_SECONDS ) def Done( self ):