From a62eb3c28bdfac7bbcc2fdfe62b18594123d15b0 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Wed, 18 Oct 2017 23:41:14 +0100 Subject: [PATCH] Move the thread joining into the LanguageServerConnection to avoid exposing it to users --- ycmd/completers/java/java_completer.py | 2 -- .../language_server/language_server_completer.py | 14 +++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ycmd/completers/java/java_completer.py b/ycmd/completers/java/java_completer.py index 011238f08c..203fbd668f 100644 --- a/ycmd/completers/java/java_completer.py +++ b/ycmd/completers/java/java_completer.py @@ -426,7 +426,6 @@ def _StopServerCleanly( self ): timeout = 5 ) if self._connection: - self._connection.join() self._connection.Close() _logger.info( 'jdt.ls Language server stopped' ) @@ -446,7 +445,6 @@ def _StopServerForcefully( self ): timeout = 5 ) if self._connection: - self._connection.join() self._connection.Close() _logger.info( 'jdt.ls Language server killed' ) diff --git a/ycmd/completers/language_server/language_server_completer.py b/ycmd/completers/language_server/language_server_completer.py index 65dcf14e6e..978d69b39b 100644 --- a/ycmd/completers/language_server/language_server_completer.py +++ b/ycmd/completers/language_server/language_server_completer.py @@ -179,9 +179,8 @@ class LanguageServerConnection( threading.Thread ): - Call stop() prior to shutting down the downstream server (see LanguageServerCompleter.ShutdownServer to do that part) - - Call join() after closing down the downstream server to wait for this - thread to exit - - Call Close() to close any remaining streams + - Call Close() to close any remaining streams. Do this in a request thread. + DO NOT CALL THIS FROM THE DISPATCH THREAD. Footnote: Why does this interface exist? @@ -202,7 +201,7 @@ def _TryServerConnectionBlocking( self ): @abc.abstractmethod - def Close( self ): + def _Close( self ): pass @@ -254,6 +253,11 @@ def stop( self ): self._stop_event.set() + def Close( self ): + self.join() + self._Close() + + def IsStopped( self ): return self._stop_event.is_set() @@ -452,7 +456,7 @@ def _TryServerConnectionBlocking( self ): return True - def Close( self ): + def _Close( self ): if not self._server_stdin.closed: self._server_stdin.close()