From f6d5f68d6b368f2419eb2e93f0ef61c407f59801 Mon Sep 17 00:00:00 2001 From: micbou Date: Sat, 5 Mar 2016 22:13:32 +0100 Subject: [PATCH] Catch ReadTimeout exception on requests --- python/ycm/client/command_request.py | 5 +++-- python/ycm/client/completer_available_request.py | 4 +++- python/ycm/client/completion_request.py | 4 +++- python/ycm/client/event_notification.py | 6 +++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/python/ycm/client/command_request.py b/python/ycm/client/command_request.py index 11909746..323054d3 100644 --- a/python/ycm/client/command_request.py +++ b/python/ycm/client/command_request.py @@ -23,11 +23,12 @@ from future import standard_library standard_library.install_aliases() from builtins import * # noqa +from requests.exceptions import ReadTimeout import vim + from ycmd.responses import ServerError from ycm.client.base_request import ( BaseRequest, BuildRequestData, HandleServerException ) - from ycm import vimsupport from ycmd.utils import ToUnicode @@ -56,7 +57,7 @@ class CommandRequest( BaseRequest ): try: self._response = self.PostDataToHandler( request_data, 'run_completer_command' ) - except ServerError as e: + except ( ServerError, ReadTimeout ) as e: HandleServerException( e ) diff --git a/python/ycm/client/completer_available_request.py b/python/ycm/client/completer_available_request.py index 9e98da0e..48fdf858 100644 --- a/python/ycm/client/completer_available_request.py +++ b/python/ycm/client/completer_available_request.py @@ -23,6 +23,8 @@ 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, BuildRequestData, HandleServerException ) from ycmd.responses import ServerError @@ -40,7 +42,7 @@ class CompleterAvailableRequest( BaseRequest ): try: self._response = self.PostDataToHandler( request_data, 'semantic_completion_available' ) - except ServerError as e: + except ( ServerError, ReadTimeout ) as e: HandleServerException( e ) diff --git a/python/ycm/client/completion_request.py b/python/ycm/client/completion_request.py index faf3c188..bf169127 100644 --- a/python/ycm/client/completion_request.py +++ b/python/ycm/client/completion_request.py @@ -23,6 +23,8 @@ from future import standard_library standard_library.install_aliases() from builtins import * # noqa +from requests.exceptions import ReadTimeout + from ycmd.utils import ToUnicode from ycm.client.base_request import ( BaseRequest, JsonFromFuture, HandleServerException, @@ -59,7 +61,7 @@ class CompletionRequest( BaseRequest ): HandleServerException( MakeServerException( e ) ) return JsonFromFuture( self._response_future )[ 'completions' ] - except ServerError as e: + except ( ServerError, ReadTimeout ) as e: HandleServerException( e ) return [] diff --git a/python/ycm/client/event_notification.py b/python/ycm/client/event_notification.py index 5537f5b8..b9a60d18 100644 --- a/python/ycm/client/event_notification.py +++ b/python/ycm/client/event_notification.py @@ -23,6 +23,8 @@ from future import standard_library standard_library.install_aliases() from builtins import * # noqa +from requests.exceptions import ReadTimeout + from ycm import vimsupport from ycmd.responses import UnknownExtraConf, ServerError from ycm.client.base_request import ( BaseRequest, BuildRequestData, @@ -66,7 +68,7 @@ class EventNotification( BaseRequest ): _LoadExtraConfFile( e.extra_conf_file ) else: _IgnoreExtraConfFile( e.extra_conf_file ) - except ServerError as e: + except ( ServerError, ReadTimeout ) as e: HandleServerException( e ) return self._cached_response if self._cached_response else [] @@ -76,10 +78,12 @@ def SendEventNotificationAsync( event_name, extra_data = None ): event = EventNotification( event_name, extra_data ) event.Start() + def _LoadExtraConfFile( filepath ): BaseRequest.PostDataToHandler( { 'filepath': filepath }, 'load_extra_conf_file' ) + def _IgnoreExtraConfFile( filepath ): BaseRequest.PostDataToHandler( { 'filepath': filepath }, 'ignore_extra_conf_file' )