Repository: spyder-ide/spyder

Issue:
Bug: Code style linting is ignored after Spyder restart
### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
The far left part of the editor displays yellow triangles that indicated pycodestyle warnings. 
When I disable some of these warnings with e.g.
Tools -> Preferences -> Completion and linting -> Code Style [x] Enable code style linting -> Ignore the following warnings: "W291" 
the yellow triangles disappear as desired. 
The problem: When I restart Spyder the yellow warnings are still displays, even though the [x] Enable code style linting is still checked and the list of ignored warnings is not changed.


### What steps reproduce the problem?

1. Tools -> Preferences -> Completion and linting -> Code Style [x] Enable code style linting -> Ignore the following warnings: "W291" 
2. Restart spyder 

### What is the expected output? What do you see instead?
I expect to not see the yellow triangles that correspond to the e.g. "W291" 
But they are still there.

### Paste Traceback/Error Below (if applicable)
N.A.

```

## Versions
* Spyder version: 4.1.5 None
* Python version: 3.7.7 64-bit
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Linux 5.4.0-48-generic

### Dependencies

# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.6.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.18.1 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
keyring                        :  None (OK)
nbconvert >=4.0                :  6.0.2 (OK)
numpydoc >=0.6.0               :  1.1.0 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.2 (OK)
pygments >=2.0                 :  2.7.0 (OK)
pylint >=1.0                   :  2.6.0 (OK)
pyls >=0.34.0;<1.0.0           :  0.35.0 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  0.7.2 (OK)
qtconsole >=4.6.0              :  4.7.7 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.2.1 (OK)
spyder_kernels >=1.9.4;<1.10.0 :  1.9.4 (OK)
watchdog                       :  None (OK)
xdg >=0.26                     :  0.26 (OK)
zmq >=17                       :  19.0.2 (OK)

# Optional:
cython >=0.21                  :  0.29.21 (OK)
matplotlib >=2.0.0             :  3.1.2 (OK)
numpy >=1.7                    :  1.15.4 (OK)
pandas >=0.13.1                :  1.1.2 (OK)
scipy >=0.17.0                 :  1.4.1 (OK)
sympy >=0.7.3                  :  1.6.2 (OK)


Discussion:
Hi @pawelusc maybe a fix for this was done in #13828. What happens if you restart the LSP using the option in the status bar?

![restart](https://user-images.githubusercontent.com/16781833/96041125-f2396980-0e30-11eb-8dec-df3d88d0d2ff.png)


Any new info that you could provide us is greatly appreciated :)
Hi @dalthviz,
thanks for this comment. I think that it is pointing in the right direction. 
I was looking at the status bar and it turns out that the "LSP Python:" is in the "starting..." status basically forever.
When I restart LSP then, in turn, the "restarting..." status stays there forever.
Could you try to run Spyder with the flag `--debug-info verbose` (something like `spyder --debug-info verbose`) and check if any traceback raise in the output. Also, are you using a custom interpreter?
Alright, I run the --debug-info verbose and the output is huge, but nothing seems to be unusual in it 
https://pastebin.com/W60NuVPN

When it comes to the interpreter, I believe that I use the standard one
![Screenshot from 2020-10-14 17-20-22](https://user-images.githubusercontent.com/65926339/96058999-9aefc500-0e41-11eb-8f05-2b7b6d2c988d.png)

Thanks @pawelusc for the info, checking it seems like an issue with `numpy`? The traceback I found shows as message `'ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject'`: 

```python
2020-10-14 17:15:00,404 [DEBUG] [spyder.plugins.completion.languageserver.client] -> 
python Response error: {'code': -32602, 'message': 'ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject',
 'data': {'traceback': [
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pyls_jsonrpc/endpoint.py", line 113, in consume\n
self._handle_request(message[\'id\'], message[\'method\'], message.get(\'params\'))\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pyls_jsonrpc/endpoint.py", line 182, in _handle_request\n
handler_result = handler(params)\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pyls_jsonrpc/dispatchers.py", line 23, in handler\n
return method(**(params or {}))\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pyls/python_ls.py", line 213, in m_initialize\n
self._hook(\'pyls_initialize\')\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pyls/python_ls.py", line 156, in _hook\n
return hook_handlers(config=self.config, workspace=workspace, document=doc, **kwargs)\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__\n
return self._hookexec(self, self.get_hookimpls(), kwargs)\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec\n
return self._inner_hookexec(hook, methods, kwargs)\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 337, in traced_hookexec\n
return outcome.get_result()\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result\n
raise ex[1].with_traceback(ex[2])\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 52, in from_call\n
result = func()\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 335, in <lambda>\n
outcome = _Result.from_call(lambda: oldcall(hook, hook_impls, kwargs))\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>\n
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall\n
return outcome.get_result()\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result\n
raise ex[1].with_traceback(ex[2])\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall\n
res = hook_impl.function(*args)\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pyls/plugins/preload_imports.py", line 31, in pyls_initialize\n
__import__(mod_name)\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pandas/__init__.py", line 30, in <module>\n
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib\n',
'  File "/home/pawel/anaconda3/lib/python3.7/site-packages/pandas/_libs/__init__.py", line 13, in <module>\n
from pandas._libs.interval import Interval\n',
'  File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval\n'
]}}

```

Could you see if updating `numpy` helps @pawelusc ? Thanks!
@dalthviz, to avoid this issue, we should add a try/except around the method in the PyLS that preload modules. That seems to be placed here:

    pyls/plugins/preload_imports.py

Could you do that?
Done @ccordoba12 

Resolving patch:
diff --git a/external-deps/python-language-server/pyls/plugins/preload_imports.py b/external-deps/python-language-server/pyls/plugins/preload_imports.py
--- a/external-deps/python-language-server/pyls/plugins/preload_imports.py
+++ b/external-deps/python-language-server/pyls/plugins/preload_imports.py
@@ -30,5 +30,8 @@ def pyls_initialize(config):
         try:
             __import__(mod_name)
             log.debug("Preloaded module %s", mod_name)
-        except ImportError:
+        except Exception:  # pylint: disable=broad-except
+            # Catch any exception since not only ImportError can be raised here
+            # For example, old versions of NumPy can cause a ValueError.
+            # See spyder-ide/spyder#13985
             pass


Test patch: