Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Kill LSP transport layer if Spyder gets killed #10111

Merged
merged 17 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions continuous_integration/azure/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ if %USE_CONDA% == yes (
pip install -q --no-deps git+https://github.com/spyder-ide/spyder-kernels
if errorlevel 1 exit 1

:: Install python-language-server from master
pip install -q --no-deps git+https://github.com/palantir/python-language-server
if errorlevel 1 exit 1

:: Install codecov
pip install -q codecov
if errorlevel 1 exit 1
6 changes: 6 additions & 0 deletions continuous_integration/azure/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ if [ "$USE_CONDA" = "yes" ]; then

# Install spyder-kernels from Github with no deps
pip install -q --no-deps git+https://github.com/spyder-ide/spyder-kernels

# Install python-language-server from Github with no deps
pip install -q --no-deps git+https://github.com/palantir/python-language-server
else
# Github backend tests are failing with 1.1.1d
conda install -q -y openssl=1.1.1c
Expand All @@ -42,4 +45,7 @@ else

# Install spyder-kernels from Github
pip install -q git+https://github.com/spyder-ide/spyder-kernels

# Install python-language-server from Github
pip install -q git+https://github.com/palantir/python-language-server
fi
6 changes: 6 additions & 0 deletions continuous_integration/travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ if [ "$USE_CONDA" = "yes" ]; then

# Install spyder-kernels from Github with no deps
pip install -q --no-deps git+https://github.com/spyder-ide/spyder-kernels

# Install python-language-server from Github with no deps
pip install -q --no-deps git+https://github.com/palantir/python-language-server
else
# Downgrade to Python 3.7.3 because 3.7.4 is not pulling
# wheels for all packages
Expand Down Expand Up @@ -67,6 +70,9 @@ else
# Install spyder-kernels from Github
pip install -q git+https://github.com/spyder-ide/spyder-kernels

# Install python-language-server from Github
pip install -q git+https://github.com/palantir/python-language-server

# Install coveralls
pip install -q coveralls
fi
3 changes: 2 additions & 1 deletion requirements/conda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ atomicwrites
chardet >=2.0.0
cloudpickle
diff-match-patch
jedi =0.14.1
keyring
nbconvert
numpydoc
Expand All @@ -12,7 +13,7 @@ pygments >=2.0
pylint
pympler
pyqt <5.13
python-language-server >=0.28.2,<0.29.0
python-language-server >=0.29.3,<0.30.0
pyxdg
pyzmq
qdarkstyle >=2.7
Expand Down
51 changes: 24 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,41 +200,38 @@ def run(self):
import setuptools # analysis:ignore

install_requires = [
'cloudpickle',
'pygments>=2.0',
'qtconsole>=4.5.5',
'nbconvert',
'sphinx',
'pylint',
'psutil',
'qtawesome>=0.5.7',
'qtpy>=1.5.0',
'pickleshare',
'pyzmq',
'chardet>=2.0.0',
'numpydoc',
'spyder-kernels>=1.6.0,<1.7.0',
'qdarkstyle>=2.7',
'atomicwrites',
'chardet>=2.0.0',
'cloudpickle',
'diff-match-patch',
'watchdog',
# This is here until Jedi 0.15+ fixes completions for
# Numpy and Pandas
'jedi==0.14.1',
# Don't require keyring for Python 2 and Linux
# because it depends on system packages
'keyring;sys_platform!="linux2"',
# Packages for pyqt5 are only available in
# Python 3
'pyqt5<5.13;python_version>="3"',
# pyqt5 5.12 split WebEngine into the
# pyqtwebengine module
'pyqtwebengine<5.13;python_version>="3"',
# Pyls with all its dependencies
'python-language-server[all]>=0.28.2,<0.29.0',
'nbconvert',
'numpydoc',
# Required to get SSH connections to remote kernels
'pexpect',
'paramiko;platform_system=="Windows"',
# Required for accesing xdg spec on Linux
'pexpect',
'pickleshare',
'psutil',
'pygments>=2.0',
'pylint',
'pympler',
'pyqt5<5.13;python_version>="3"',
'pyqtwebengine<5.13;python_version>="3"',
'python-language-server[all]>=0.29.3,<0.30.0',
'pyxdg>=0.26;platform_system=="Linux"',
'pympler'
'pyzmq',
'qdarkstyle>=2.7',
'qtawesome>=0.5.7',
'qtconsole>=4.5.5',
'qtpy>=1.5.0',
'sphinx',
'spyder-kernels>=1.6.0,<1.7.0',
'watchdog',
]

extras_require = {
Expand Down
8 changes: 7 additions & 1 deletion spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,12 +1469,18 @@ def set_window_title(self):

def report_missing_dependencies(self):
"""Show a QMessageBox with a list of missing hard dependencies"""
# Declare dependencies before trying to detect the missing ones
dependencies.declare_dependencies()
missing_deps = dependencies.missing_dependencies()

if missing_deps:
# Fix html formatting. The last 4 chars correspond to a
# '<br>' added by missing_dependencies
missing_deps = missing_deps[:-4].replace('<', '&lt;')

QMessageBox.critical(self, _('Error'),
_("<b>You have missing dependencies!</b>"
"<br><br><tt>%s</tt><br>"
"<br><br><tt>%s</tt><br><br>"
"<b>Please install them to avoid this message.</b>"
"<br><br>"
"<i>Note</i>: Spyder could work without some of these "
Expand Down
2 changes: 1 addition & 1 deletion spyder/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
PANDAS_REQVER = '>=0.13.1'
NUMPY_REQVER = '>=1.7'
SCIPY_REQVER = '>=0.17.0'
PYLS_REQVER = '>=0.28.2;<0.29.0'
PYLS_REQVER = '>=0.29.2;<0.30.0'



Expand Down
3 changes: 2 additions & 1 deletion spyder/plugins/completion/languageserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@ def perform_request(self, method, params):
@handles(SERVER_READY)
@send_request(method=LSPRequestTypes.INITIALIZE)
def initialize(self, *args, **kwargs):
pid = self.transport_client.pid if not self.external_server else None
params = {
'processId': self.transport_client.pid,
'processId': pid,
'rootUri': pathlib.Path(osp.abspath(self.folder)).as_uri(),
'capabilities': self.client_capabilites,
'trace': TRACE
Expand Down
5 changes: 3 additions & 2 deletions spyder/plugins/completion/languageserver/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,10 @@ def generate_python_config(self):
# Setup options in json
python_config['cmd'] = cmd
if host in self.LOCALHOST and not stdio:
python_config['args'] = '--host {host} --port {port} --tcp'
python_config['args'] = ('--host {host} --port {port} --tcp '
'--check-parent-process')
else:
python_config['args'] = ''
python_config['args'] = '--check-parent-process'
python_config['external'] = external_server
python_config['stdio'] = stdio
python_config['host'] = host
Expand Down
30 changes: 28 additions & 2 deletions spyder/plugins/completion/languageserver/transport/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import psutil
import signal
import threading
from functools import partial

# Local imports
Expand All @@ -31,6 +32,8 @@

logger = logging.getLogger(__name__)

PARENT_PROCESS_WATCH_INTERVAL = 3 # 3 s


parser = argparse.ArgumentParser(
description='ZMQ Python-based MS Language-Server v3.0 client for Spyder')
Expand Down Expand Up @@ -120,6 +123,8 @@ def restore(self):
extra_args = ' '.join(extra_args)
logger.debug(extra_args)
process = psutil.Process()
parent_pid = process.ppid()

sig_manager = SignalManager()
if args.stdio_server:
LanguageServerClient = partial(StdioLanguageServerClient,
Expand All @@ -132,12 +137,33 @@ def restore(self):
client = LanguageServerClient(zmq_in_port=args.zmq_in_port,
zmq_out_port=args.zmq_out_port)
client.start()
is_alive = True

def watch_parent_process(pid):
"""
Exit when the given pid is not alive.

Code taken from the Python Language Server project.
"""
global is_alive
if not psutil.pid_exists(pid):
logger.info("parent process %s is not alive, exiting!", pid)
is_alive = False
if is_alive:
threading.Timer(PARENT_PROCESS_WATCH_INTERVAL,
watch_parent_process, args=[pid]).start()

watching_thread = threading.Thread(
target=watch_parent_process, args=(parent_pid,))
watching_thread.daemon = True
watching_thread.start()

try:
while True:
while is_alive:
client.listen()
except TerminateSignal:
pass
client.stop()
# sig_manager.restore()

process.terminate()
process.wait()
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def stop(self):
logger.info('Closing consumer thread...')
self.reading_thread.stop()
logger.debug('Joining thread...')
self.reading_thread.join()
logger.debug('Exit routine should be complete')

def transport_send(self, content_length, body):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def stop(self):
self.socket.close()
logger.info('Closing consumer thread...')
self.reading_thread.stop()
logger.debug('Joining thread...')
self.reading_thread.join()
logger.debug('Exit routine should be complete')

def transport_send(self, content_length, body):
Expand Down