python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

Python Language Server crashes the system by infinite analysis in the background

Open NikTarasov opened this issue 7 years ago • 7 comments

Issue Type: Bug

  1. Create a virtual env (e.g. with pipenv)
  2. install plotly
  3. create an empty python file with one line: import plotly
  4. The extension will consume all cpu and RAM and crash the whole system

Extension version: 2019.4.11987 VS Code version: Code 1.33.1 (51b0b28134d51361cf996d2f0a1c698247aeabd8, 2019-04-11T08:22:55.268Z) OS version: Darwin x64 18.5.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 x 2800)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 4, 4, 7
Memory (System) 16.00GB (4.51GB free)
Process Argv
Screen Reader no
VM 0%

NikTarasov avatar Apr 30 '19 14:04 NikTarasov

Can you provide your language server version and your environment definition (pip freeze, a Pipfile, etc)?

I can't seem to reproduce this in an environment with just plotly installed and import plotly.

jakebailey avatar Apr 30 '19 16:04 jakebailey

Apologies, my bad, I didn't describe the environment correctly. I know that the plotly package is the culprit, as the language server gets stuck queuing modules from plotly, but it's a bit more complicated than I described initially:

Extension version: 2019.4.11987 Language Server: 0.2.66 pipfile:

name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
jupyter = "*"
numpy = "*"
boto3 = "*"
pandas = "*"
scipy = "*"
plotly = "*"
matplotlib = "*"
requests = "*"
pymc3 = "*"
pylint = "*"
autopep8 = "*"

[requires]
python_version = "3.7"

the python file (running it like a jupyter notebook) contained the following:

#%%
import numpy as np
import pandas as pd
import pickle
import boto3
import json
from os import path
from boto3.dynamodb.conditions import Key, Attr
from plotly.offline import iplot, init_notebook_mode
import plotly.graph_objs as go
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import matplotlib as mpl
import pymc3 as pm
from pymc3 import Model, Normal, Slice
from pymc3 import sample
from pymc3 import traceplot
from pymc3.distributions import Interpolated
from theano import as_op
import theano.tensor as tt
from scipy import stats

init_notebook_mode(connected=True)
# %matplotlib inline
pd.set_option('display.max_rows', 1000)  # or 1000
pd.set_option('display.max_colwidth', 50)  # or 1000

Opening a file like that would result in a really long analysis. I guess when there are more cells with import statements, and other code, the Language Server goes into a circular analysis mode. I cannot post the original file, there is some proprietary code, but I will try to recreate it with some generic code.

NikTarasov avatar Apr 30 '19 17:04 NikTarasov

Hmm, on my machine it completes in about a minute or so, without hanging.

Am I correct in assuming you enabled the higher logging level? (If you were able to see something about plotly, that is.) Do you see the message "reloading modules" often, or not at all?

Does the code you're writing write out any files somewhere within the workspace?

jakebailey avatar Apr 30 '19 20:04 jakebailey

I did enable the higher logging level. No reloading at all. I also made a file which consistently sends the Language Server into a cycle: gist To reproduce create a new folder, create a new pipenv (pipfile in the gist), add test.py to the folder. No execution needed. Just opening the folder as a new window and the file in VS Code is enough. Hope this helps

NikTarasov avatar May 01 '19 10:05 NikTarasov

This one also completes for me (though does take a bit longer). I'll see about testing it on macOS to see if it's a platform thing.

jakebailey avatar May 02 '19 21:05 jakebailey

It is possible that the Language Server actually completes the analysis eventually, but the problem is that it hangs/crashes the system in the process: memory usage

NikTarasov avatar May 10 '19 10:05 NikTarasov

It seems that the issue has been resolved in the latest version. Analysis is orders of magnitude faster and doesn't hang the machine. I think this issue can be closed.

NikTarasov avatar May 28 '19 13:05 NikTarasov