Repository: spyder-ide/spyder

Issue:
Spyder freezes when trying to connect to an LSP server
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->


I cloned the spyder-mast and installed all dependencies, but it is freezing until I make a ctrl+c.

I start the bootstrap in the debug mode and get the the following message:

2019-09-16 13:12:47,681 [DEBUG] [spyder.plugins.editor.plugin] -> python completion server request: 'textDocument/didOpen'
2019-09-16 13:12:47,682 [DEBUG] [spyder.plugins.completion.languageserver.client] -> python request: textDocument/didOpen
^CTraceback (most recent call last):
  File "/home/hofsaess/gittest/spyder/spyder/plugins/editor/plugin.py", line 318, in send_completion_request
    self.main.completions.send_request(language, request, params)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/plugin.py", line 185, in send_request
    language, req_type, req, req_id)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/plugin.py", line 255, in send_request
    client.perform_request(request, params)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/client.py", line 356, in perform_request
    _id = handler(params)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/decorators.py", line 42, in wrapper
    _id = self.send(method, params, kind)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/client.py", line 290, in send
    self.zmq_out_socket.send_pyobj(msg)
  File "/usr/local/lib/python3.7/site-packages/zmq/sugar/socket.py", line 611, in send_pyobj
    return self.send(msg, flags=flags, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/zmq/sugar/socket.py", line 400, in send
    return super(Socket, self).send(data, flags=flags, copy=copy, track=track)
  File "zmq/backend/cython/socket.pyx", line 728, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 775, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 242, in zmq.backend.cython.socket._send_copy
  File "zmq/backend/cython/checkrc.pxd", line 12, in zmq.backend.cython.checkrc._check_rc
KeyboardInterrupt


My list of dependencies is:

cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.6.0 (OK)
sphinx >=0.6.6               :  2.2.0 (OK)
pylint >=0.25                :  2.3.1 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.5.0;<2.0.0:  1.5.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.4 (OK)
cython >=0.21                :  0.29.13 (OK)
IPython >=4.0                :  7.8.0 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
pandas >=0.13.1              :  0.25.1 (OK)
numpy >=1.7                  :  1.17.2 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
pyls >=0.28.2;<0.29.0        :  0.28.3 (OK)
xdg >=0.26                   :  0.26 (OK)





## Versions

* Spyder version: 4.0.0.dev0 ac379b3
* Python version: 3.7.2
* Qt version: 5.9.3
* PyQt5 version: 5.9.2
* Operating System: Linux 4.15.0-54-generic

### Dependencies

```
cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.6.0 (OK)
sphinx >=0.6.6               :  2.2.0 (OK)
pylint >=0.25                :  2.3.1 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.5.0;<2.0.0:  1.5.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.4 (OK)
cython >=0.21                :  0.29.13 (OK)
IPython >=4.0                :  7.8.0 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
pandas >=0.13.1              :  0.25.1 (OK)
numpy >=1.7                  :  1.17.2 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
pyls >=0.28.2;<0.29.0        :  0.28.3 (OK)
xdg >=0.26                   :  0.26 (OK)
```



Discussion:
> /usr/local/lib/python3.7/site-packages/zmq/sugar/socket.py

This line (present in your traceback above) shows that you used `sudo pip install` to install Spyder (or some of our dependencies). That's very bad because it mixes system Python packages with packages installed by pip, which is the probable cause of this error.

To fix this, please:

1. Remove all packages you installed in `/usr/local/lib` to avoid similar failures like this (with Spyder or other packages) in the future.
2. Use a virtualenv or venv to install Spyder (if you want to keep using pip), or simply use Anaconda (in case things give you more problems).
I created a virtuelenv and installed all packages, but I had the same problem. 

Looks like there is also an other problem.

Traceback (most recent call last):
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/spyder/plugins/editor/plugin.py", line 318, in send_completion_request
    self.main.completions.send_request(language, request, params)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/spyder/plugins/completion/plugin.py", line 185, in send_request
    language, req_type, req, req_id)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/spyder/plugins/completion/languageserver/plugin.py", line 255, in send_request
    client.perform_request(request, params)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/spyder/plugins/completion/languageserver/client.py", line 356, in perform_request
    _id = handler(params)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/spyder/plugins/completion/languageserver/decorators.py", line 42, in wrapper
    _id = self.send(method, params, kind)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/spyder/plugins/completion/languageserver/client.py", line 290, in send
    self.zmq_out_socket.send_pyobj(msg)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/zmq/sugar/socket.py", line 611, in send_pyobj
    return self.send(msg, flags=flags, **kwargs)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/zmq/sugar/socket.py", line 400, in send
    return super(Socket, self).send(data, flags=flags, copy=copy, track=track)
  File "zmq/backend/cython/socket.pyx", line 728, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 775, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 247, in zmq.backend.cython.socket._send_copy
  File "zmq/backend/cython/socket.pyx", line 242, in zmq.backend.cython.socket._send_copy
  File "zmq/backend/cython/checkrc.pxd", line 25, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Socket operation on non-socket



I was able to reproduce this but you didn't mention how you got into this situation. This happens when you try to connect to an external LSP server, then close Spyder, then close the server and start Spyder again.

That's why we ask for a detailed description of the problem. Fortunately I was testing something similar for PR #10211, else we have dismissed it as a very odd issue.

@andfoy, what can we do about this one?
@hofsaess, to fix this for now please run

    spyder --reset
And start Spyder again.
@andfoy, I think we really need to check if `host:port` is at least listening. Here's some code for that:

https://gist.github.com/betrcode/0248f0fda894013382d7
Hi, what ist an external lsp Server? I so Not think that i' m running one.

I also tried the reset flag, but no success.



Carlos Cordoba <notifications@github.com> schrieb am Mo., 16. Sep. 2019,
16:20:

> I was able to reproduce this but you didn't mention how you got into this
> situation. This happens when you try to connect to an external LSP server,
> then close Spyder, then close the server and start Spyder again.
>
> That's why we ask for a detailed description of the problem. Fortunately I
> was testing something similar for PR #10211
> <https://github.com/spyder-ide/spyder/pull/10211>, else we have dismissed
> it as a very odd issue.
>
> @andfoy <https://github.com/andfoy>, what can we do about this one?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/10209?email_source=notifications&email_token=AFSLEYBTUFWRGD4FTDAVNCLQJ6I3HA5CNFSM4IXA3YNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6ZJZBI#issuecomment-531799173>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AFSLEYA2Y6LBKVMCAUMDJW3QJ6I3HANCNFSM4IXA3YNA>
> .
>

Ok, sorry, I thought that was the problem. Do you have very strict iptables (or another firewall) rules? I say it because that could block communications between our client and the code completion server.

Also, please open the file `~/.config/spyder-py3-dev/config/spyder.ini` with another text editor, look for an entry called `advanced/stdio` and set it to `True`. That could also solve your problem.


This also happens when the PyLS dies in the background while Spyder is running.
Another (even simpler) case that generates this: starting Spyder in a terminal without freeing it (i.e. as `spyder` and not `spyder &`), then pressing `Ctrl+C` on the terminal.

That generates a `KeyboardInterrupt` that's handled by our LSP client, which kills our transport layer and the PyLS server connected to it.

After that, pressing any key in the editor causes a freeze too.
So, this happens also with local servers, or should be tracking it separately?
I think the issue is the same regardless if the server is local or external: when there's no PyLS server to talk to, writing anything in the editor freezes Spyder.

However, I think you could require two different PRs to solve this: one that verifies that an external server is listening at `host:port` before trying to connect to it; and another one that starts a new server and connects to it if the current one dies or gets killed.

For simplicity, let's track everything here and let's make the second PR to close this issue.
Hi,

I update my git clone (git pull) and tried to start the spyder-ide(python3 bootstrap.py --debug &;  Revision 1c7b223, Branch: master), but the failure also exists.

The gui was starting, but it's freezing, until I make a ctrl+c. 
The debug output is:

2019-09-23 10:31:17,410 [DEBUG] [spyder.plugins.editor.panels.manager] -> Refresh panels
2019-09-23 10:31:17,439 [DEBUG] [spyder.plugins.editor.plugin] -> Start completion server for /home/hofsaess/.config/spyder-py3-dev/temp.py [Python]
2019-09-23 10:31:17,440 [DEBUG] [spyder.plugins.editor.plugin] -> Python completion server is ready
2019-09-23 10:31:17,440 [DEBUG] [spyder.plugins.editor.widgets.codeeditor] -> Completions services available for: /home/hofsaess/.config/spyder-py3-dev/temp.py
2019-09-23 10:31:17,440 [DEBUG] [spyder.plugins.editor.plugin] -> python completion server request: 'textDocument/didOpen'
2019-09-23 10:31:17,440 [DEBUG] [spyder.plugins.completion.languageserver.client] -> python request: textDocument/didOpen
^CTraceback (most recent call last):
  File "/home/hofsaess/gittest/spyder/spyder/plugins/editor/plugin.py", line 318, in send_completion_request
    self.main.completions.send_request(language, request, params)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/plugin.py", line 185, in send_request
    language, req_type, req, req_id)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/plugin.py", line 300, in send_request
    client.perform_request(request, params)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/client.py", line 359, in perform_request
    _id = handler(params)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/decorators.py", line 42, in wrapper
    _id = self.send(method, params, kind)
  File "/home/hofsaess/gittest/spyder/spyder/plugins/completion/languageserver/client.py", line 293, in send
    self.zmq_out_socket.send_pyobj(msg)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/zmq/sugar/socket.py", line 602, in send_pyobj
    return self.send(msg, flags=flags, **kwargs)
  File "/home/hofsaess/scripts37/swe/lib/python3.7/site-packages/zmq/sugar/socket.py", line 391, in send
    return super(Socket, self).send(data, flags=flags, copy=copy, track=track)
  File "zmq/backend/cython/socket.pyx", line 727, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 774, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 244, in zmq.backend.cython.socket._send_copy
  File "zmq/backend/cython/checkrc.pxd", line 12, in zmq.backend.cython.checkrc._check_rc
KeyboardInterrupt
2019-09-23 10:31:42,118 [DEBUG] [spyder.plugins.editor.widgets.editor] -> Set focus to: /home/hofsaess/.config/spyder-py3-dev/temp.py
2019-09-23 10:31:42,119 [DEBUG] [spyder.plugins.editor.widgets.editor] -> Current changed: 0 - /home/hofsaess/.config/spyder-py3-dev/temp.py

After I typing in the code editor, the gui is freezing again.

The firewall was disabled. 

What I doing wrong? What can I try?








You need to be more specific: when does the interface freeze exactly? I mean, at what point while Spyde is loading it freezes?
Hi,

I add a screenshot of the freezing status and the tail of the log.

2019-09-23 15:12:55,885 [INFO] [spyder.app.mainwindow] -> Loading project
explorer...
2019-09-23 15:12:58,097 [INFO] [spyder.app.mainwindow] -> Loading
third-party plugins...
2019-09-23 15:12:58,152 [INFO] [spyder.app.mainwindow] -> Setting up main
window...
2019-09-23 15:12:58,323 [INFO] [spyder.app.mainwindow] -> Setting up
window...
2019-09-23 15:12:58,339 [INFO] [spyder.app.mainwindow] -> *** End of
MainWindow setup ***
2019-09-23 15:12:58,804 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:12:59,044 [INFO] [spyder.app.mainwindow] -> Deleting previous
Spyder instance LSP logs...
2019-09-23 15:12:59,264 [DEBUG] [traitlets] -> Using default logger
2019-09-23 15:13:01,072 [DEBUG] [traitlets] -> Starting kernel:
['/home/hofsaess/scripts37/swe/bin/python3', '-m',
'spyder_kernels.console', '-f',
'/home/hofsaess/.local/share/jupyter/runtime/kernel-1cbc1a238d42.json']
2019-09-23 15:13:01,090 [DEBUG] [traitlets] -> Connecting to: tcp://
127.0.0.1:44845
2019-09-23 15:13:01,223 [DEBUG] [traitlets] -> connecting heartbeat channel
to tcp://127.0.0.1:39431
2019-09-23 15:13:01,224 [DEBUG] [asyncio] -> Using selector: EpollSelector
2019-09-23 15:13:01,225 [DEBUG] [asyncio] -> Using selector: EpollSelector
2019-09-23 15:13:01,225 [DEBUG] [traitlets] -> connecting shell channel to
tcp://127.0.0.1:44267
2019-09-23 15:13:01,226 [DEBUG] [traitlets] -> Connecting to: tcp://
127.0.0.1:44267
2019-09-23 15:13:01,227 [DEBUG] [traitlets] -> connecting iopub channel to
tcp://127.0.0.1:46643
2019-09-23 15:13:01,227 [DEBUG] [traitlets] -> Connecting to: tcp://
127.0.0.1:46643
2019-09-23 15:13:01,228 [DEBUG] [traitlets] -> connecting stdin channel to
tcp://127.0.0.1:56933
2019-09-23 15:13:01,228 [DEBUG] [traitlets] -> Connecting to: tcp://
127.0.0.1:56933
2019-09-23 15:13:01,332 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel EdgeLine at floating
2019-09-23 15:13:01,332 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,334 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel EdgeLine installed
2019-09-23 15:13:01,334 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel IndentationGuide at floating
2019-09-23 15:13:01,334 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,335 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel IndentationGuide installed
2019-09-23 15:13:01,335 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel FoldingPanel at left
2019-09-23 15:13:01,335 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,336 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel FoldingPanel installed
2019-09-23 15:13:01,336 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel DebuggerPanel at left
2019-09-23 15:13:01,337 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,337 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel DebuggerPanel installed
2019-09-23 15:13:01,338 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel LineNumberArea at left
2019-09-23 15:13:01,338 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,339 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel LineNumberArea installed
2019-09-23 15:13:01,339 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel ClassFunctionDropdown at top
2019-09-23 15:13:01,349 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,350 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel ClassFunctionDropdown installed
2019-09-23 15:13:01,351 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel ScrollFlagArea at right
2019-09-23 15:13:01,351 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,351 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel ScrollFlagArea installed
2019-09-23 15:13:01,351 [DEBUG] [spyder.api.panel] -> ScrollFlagArea
visibility changed
2019-09-23 15:13:01,351 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,352 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,366 [DEBUG] [spyder.plugins.editor.extensions.manager]
-> adding extension CloseQuotesExtension
2019-09-23 15:13:01,367 [DEBUG] [spyder.plugins.editor.extensions.manager]
-> adding extension SnippetsExtension
2019-09-23 15:13:01,367 [DEBUG] [spyder.plugins.editor.extensions.manager]
-> adding extension CloseBracketsExtension
2019-09-23 15:13:01,367 [DEBUG] [spyder.api.panel] -> DebuggerPanel
visibility changed
2019-09-23 15:13:01,368 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,368 [DEBUG] [spyder.api.panel] -> FoldingPanel
visibility changed
2019-09-23 15:13:01,368 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,369 [DEBUG] [spyder.api.panel] -> ScrollFlagArea
visibility changed
2019-09-23 15:13:01,369 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,369 [DEBUG] [spyder.api.panel] -> EdgeLine visibility
changed
2019-09-23 15:13:01,370 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,370 [DEBUG] [spyder.api.panel] -> IndentationGuide
visibility changed
2019-09-23 15:13:01,370 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,371 [DEBUG] [spyder.api.panel] -> LineNumberArea
visibility changed
2019-09-23 15:13:01,371 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,376 [DEBUG] [spyder.api.panel] -> ClassFunctionDropdown
visibility changed
2019-09-23 15:13:01,376 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,378 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,476 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,560 [DEBUG] [spyder.plugins.editor.widgets.editor] ->
Call ThreadManager's 'close_threads'
2019-09-23 15:13:01,707 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel EdgeLine at floating
2019-09-23 15:13:01,707 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,708 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel EdgeLine installed
2019-09-23 15:13:01,708 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel IndentationGuide at floating
2019-09-23 15:13:01,708 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,709 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel IndentationGuide installed
2019-09-23 15:13:01,709 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel FoldingPanel at left
2019-09-23 15:13:01,709 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,709 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel FoldingPanel installed
2019-09-23 15:13:01,710 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel DebuggerPanel at left
2019-09-23 15:13:01,710 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,711 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel DebuggerPanel installed
2019-09-23 15:13:01,711 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel LineNumberArea at left
2019-09-23 15:13:01,711 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,712 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel LineNumberArea installed
2019-09-23 15:13:01,712 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel ClassFunctionDropdown at top
2019-09-23 15:13:01,719 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,720 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel ClassFunctionDropdown installed
2019-09-23 15:13:01,721 [DEBUG] [spyder.plugins.editor.panels.manager] ->
adding panel ScrollFlagArea at right
2019-09-23 15:13:01,721 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,722 [DEBUG] [spyder.plugins.editor.panels.manager] ->
panel ScrollFlagArea installed
2019-09-23 15:13:01,722 [DEBUG] [spyder.api.panel] -> ScrollFlagArea
visibility changed
2019-09-23 15:13:01,722 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,722 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,729 [DEBUG] [spyder.plugins.editor.extensions.manager]
-> adding extension CloseQuotesExtension
2019-09-23 15:13:01,729 [DEBUG] [spyder.plugins.editor.extensions.manager]
-> adding extension SnippetsExtension
2019-09-23 15:13:01,729 [DEBUG] [spyder.plugins.editor.extensions.manager]
-> adding extension CloseBracketsExtension
2019-09-23 15:13:01,736 [DEBUG] [spyder.api.panel] -> EdgeLine visibility
changed
2019-09-23 15:13:01,737 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,737 [DEBUG] [spyder.api.panel] -> IndentationGuide
visibility changed
2019-09-23 15:13:01,737 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,737 [DEBUG] [spyder.api.panel] -> FoldingPanel
visibility changed
2019-09-23 15:13:01,738 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,738 [DEBUG] [spyder.api.panel] -> DebuggerPanel
visibility changed
2019-09-23 15:13:01,738 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,739 [DEBUG] [spyder.api.panel] -> LineNumberArea
visibility changed
2019-09-23 15:13:01,739 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,740 [DEBUG] [spyder.api.panel] -> ClassFunctionDropdown
visibility changed
2019-09-23 15:13:01,741 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,742 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,743 [DEBUG] [spyder.plugins.editor.widgets.editor] ->
Set focus to: None
2019-09-23 15:13:01,744 [DEBUG] [spyder.plugins.editor.widgets.editor] ->
Current changed: 0 - None
2019-09-23 15:13:01,746 [DEBUG] [spyder.api.panel] -> DebuggerPanel
visibility changed
2019-09-23 15:13:01,746 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,747 [DEBUG] [spyder.api.panel] -> FoldingPanel
visibility changed
2019-09-23 15:13:01,747 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,748 [DEBUG] [spyder.api.panel] -> ScrollFlagArea
visibility changed
2019-09-23 15:13:01,748 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,750 [DEBUG] [spyder.api.panel] -> EdgeLine visibility
changed
2019-09-23 15:13:01,750 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,751 [DEBUG] [spyder.api.panel] -> IndentationGuide
visibility changed
2019-09-23 15:13:01,751 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,752 [DEBUG] [spyder.api.panel] -> LineNumberArea
visibility changed
2019-09-23 15:13:01,752 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,758 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:01,763 [DEBUG] [spyder.api.panel] -> ClassFunctionDropdown
visibility changed
2019-09-23 15:13:01,764 [DEBUG] [spyder.plugins.editor.panels.manager] ->
Refresh panels
2019-09-23 15:13:02,006 [DEBUG] [spyder.plugins.editor.plugin] -> Start
completion server for /home/hofsaess/.config/spyder-py3-dev/temp.py [Python]
2019-09-23 15:13:02,007 [DEBUG] [spyder.plugins.editor.plugin] -> Python
completion server is ready
2019-09-23 15:13:02,007 [DEBUG] [spyder.plugins.editor.widgets.codeeditor]
-> Completions services available for:
/home/hofsaess/.config/spyder-py3-dev/temp.py
2019-09-23 15:13:02,007 [DEBUG] [spyder.plugins.editor.plugin] -> python
completion server request: 'textDocument/didOpen'
2019-09-23 15:13:02,007 [DEBUG]
[spyder.plugins.completion.languageserver.client] -> python request:
textDocument/didOpen


Hope this will help.


Am Mo., 23. Sept. 2019 um 13:49 Uhr schrieb Carlos Cordoba <
notifications@github.com>:

> You need to be more specific: when does the interface freeze exactly? I
> mean, at what point while Spyde is loading it freezes?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/10209?email_source=notifications&email_token=AFSLEYDIR2WDMQBDUDZY7O3QLCUOLA5CNFSM4IXA3YNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7KTATY#issuecomment-534065231>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AFSLEYGATDAETBSA4LAEW7TQLCUOLANCNFSM4IXA3YNA>
> .
>

> I add a screenshot of the freezing status and the tail of the log.

The tail is not enough. Please post the entire log info, but not as comment. Instead, please copy it in a file and upload it here (you can't do that by email by directly here).
Hi,

I add the screenshot and the debug output. At line 1142 is the freezing starting. 
Then I make a ctrl+c and the ipython console and the editor frame will be shown.

Hope this will help.

![spyder](https://user-images.githubusercontent.com/23376480/65489488-8b56b480-deab-11e9-92b1-eebeee94978d.png)
[spyder_debug.log](https://github.com/spyder-ide/spyder/files/3645733/spyder_debug.log)

Please look for these files and upload them here:

    /home/hofsaess/.config/spyder-py3-dev/lsp_logs/client_python_4115.log
    /home/hofsaess/.config/spyder-py3-dev/lsp_logs/server_python_4115.log

The numbers at the end could be different if you started Spyder again. If that's the case, please upload the files that you're able to find in

    /home/hofsaess/.config/spyder-py3-dev/lsp_logs/
Hi

I have attached the requested files.

[client_python_7195.log](https://github.com/spyder-ide/spyder/files/3647462/client_python_7195.log)
[server_python_7195.log](https://github.com/spyder-ide/spyder/files/3647463/server_python_7195.log)

@hofsaess, thanks!
It's clear for us now that we haven't fixed your issue yet, and that it was unrelated to the work done in PR #10278 to try to deal with it.
@steff456, please help us with this one. Please set a very strict [iptables](https://wiki.archlinux.org/index.php/iptables) rule that doesn't allow to open any port in your Linux virtual machine. Then start Spyder with stdio activated to see if you can reproduce the logs posted by @hofsaess above.

If that's the case, then I'll come up with a new PR right away to inform users that we were unable to open a port in your system and that completion will not work due to that.

----

@hofsaess, I know you said that you deactivated your firewall but I don't have any other explanation for this problem at the moment.
@ccordoba12 @hofsaess, thank you both for your work on this issue.  I am seeing the same issue on macOS.  I note in the lsp server log that the pyls server does not appear to be starting in tcp mode on 127.0.0.1.  When I start the pyls server manually in tcp mode, I am able to verify that the port is open using the port test code mentioned earlier at https://gist.github.com/betrcode/0248f0fda894013382d7.  
@gregnzice, please run `spyder --reset` and try again to see if that helps.
@ccordoba12, just ran a spyder --reset and am still getting the same result. I checked the pyls server log on a working spyder4 installation on a Windows PC and can confirm that the pyls server log states that that it is being opened in tcp mode:

2019-09-25 08:16:03,477 UTC - INFO - pyls.python_ls - Serving PythonLanguageServer on (127.0.0.1, 2087)

This is the output when I run spyder4 on the mac:

2019-09-25 08:11:31,982 UTC - INFO - pyls.python_ls - Starting PythonLanguageServer IO language server


@gregnzice, this is the same problem that @hofsaess is having, but I really don't understand how `stdio` can be selected after resetting your preferences.

Please open this file with a text editor

    ~/.spyder-py3-dev/config/spyder.ini

look for a line called `advanced/stdio`, make it `False` (it should be `True`) and start Spyder again.
@ccordoba12, I edited spyder.ini to change advanced/stdio setting to False and re-started Spyder and am still getting the same result.  I then moved .spyder-py3-dev to a temporary folder and restarted Spyder to create an entirely new .spyder-py3-dev folder with the same result.  
@ccordoba12, another update.  Went and checked the pyls server log after making the change to spyder.ini and noted that the pyls server is now starting correctly in tcp mode:

2019-09-26 08:08:23,643 UTC - INFO - pyls.python_ls - Serving PythonLanguageServer on (127.0.0.1, 2089)

However, spyder is still hanging with:

2019-09-26 08:08:25,538 [DEBUG] [spyder.plugins.completion.languageserver.client] -> python request: textDocument/didOpen
I also have the same problem infrequently (Only just after starting spyder it seems). My traceback is:

```python-traceback
Traceback (most recent call last):
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/plugin.py", line 320, in send_completion_request
    self.main.completions.send_request(language, request, params)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/plugin.py", line 216, in send_request
    language, req_type, req, req_id)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/languageserver/plugin.py", line 289, in send_request
    client.perform_request(request, params)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/languageserver/client.py", line 359, in perform_request
    _id = handler(params)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/languageserver/decorators.py", line 42, in wrapper
    _id = self.send(method, params, kind)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/languageserver/client.py", line 293, in send
    self.zmq_out_socket.send_pyobj(msg)
  File "/usr/local/lib/python3.7/site-packages/zmq/sugar/socket.py", line 606, in send_pyobj
    return self.send(msg, flags=flags, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/zmq/sugar/socket.py", line 395, in send
    return super(Socket, self).send(data, flags=flags, copy=copy, track=track)
  File "zmq/backend/cython/socket.pyx", line 725, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 772, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 242, in zmq.backend.cython.socket._send_copy
  File "zmq/backend/cython/checkrc.pxd", line 12, in zmq.backend.cython.checkrc._check_rc
KeyboardInterrupt
```

My guess is that this happens when the language server crashed for some reason.
I created https://github.com/spyder-ide/spyder/pull/10481.

Can you try if it fixes your problem?
@impact27 Just tried #10481 but am getting the same behavior as before, i.e. spyder is hanging on startup at : 
2019-10-22 09:07:05,830 [DEBUG] [spyder.plugins.completion.languageserver.client] -> python request: textDocument/didOpen

After typing Ctrl+C, I get the following traceback:

Traceback (most recent call last):
  File "/Users/Greg/Documents/GitHub_Repositories/spyder_lsp/spyder/plugins/editor/plugin.py", line 320, in send_completion_request
    self.main.completions.send_request(language, request, params)
  File "/Users/Greg/Documents/GitHub_Repositories/spyder_lsp/spyder/plugins/completion/plugin.py", line 216, in send_request
    language, req_type, req, req_id)
  File "/Users/Greg/Documents/GitHub_Repositories/spyder_lsp/spyder/plugins/completion/languageserver/plugin.py", line 289, in send_request
    client.perform_request(request, params)
  File "/Users/Greg/Documents/GitHub_Repositories/spyder_lsp/spyder/plugins/completion/languageserver/client.py", line 361, in perform_request
    _id = handler(params)
  File "/Users/Greg/Documents/GitHub_Repositories/spyder_lsp/spyder/plugins/completion/languageserver/decorators.py", line 42, in wrapper
    _id = self.send(method, params, kind)
  File "/Users/Greg/Documents/GitHub_Repositories/spyder_lsp/spyder/plugins/completion/languageserver/client.py", line 295, in send
    self.zmq_out_socket.send_pyobj(msg)
  File "/usr/local/lib/python3.7/site-packages/zmq/sugar/socket.py", line 611, in send_pyobj
    return self.send(msg, flags=flags, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/zmq/sugar/socket.py", line 400, in send
    return super(Socket, self).send(data, flags=flags, copy=copy, track=track)
  File "zmq/backend/cython/socket.pyx", line 728, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 775, in zmq.backend.cython.socket.Socket.send
  File "zmq/backend/cython/socket.pyx", line 242, in zmq.backend.cython.socket._send_copy
  File "zmq/backend/cython/checkrc.pxd", line 12, in zmq.backend.cython.checkrc._check_rc
KeyboardInterrupt
next idea:
in `spyder/plugins/completion/languageserver/transport/main.py` on the bottom of the file:
Check if `client.listen()` is thowing an exception.

I would replace lines 134 -139 by:

```
    try:
        client.start()
        while True:
            client.listen()
    except TerminateSignal:
        pass
    except Exception:
        import traceback
        with open('/Users/quentinpeter/Desktop/log.txt', 'a') as f:
            f.write(''.join(traceback.format_exc()))
```
Adjust the filename as needed 
@impact27 Replaced lines 134-139 (with updated filepath) - no change and no log file written.
Attached are the lsp client and server logs.
  
[client_python_92612.log](https://github.com/spyder-ide/spyder/files/3753750/client_python_92612.log)
[server_python_92612.log](https://github.com/spyder-ide/spyder/files/3753752/server_python_92612.log)



Resolving patch:
diff --git a/spyder/plugins/completion/languageserver/client.py b/spyder/plugins/completion/languageserver/client.py
--- a/spyder/plugins/completion/languageserver/client.py
+++ b/spyder/plugins/completion/languageserver/client.py
@@ -67,6 +67,10 @@ class LSPClient(QObject, LSPMethodProviderMixIn):
     #  facilities.
     sig_server_error = Signal(str)
 
+    #: Signal to warn the user when either the transport layer or the
+    #  server are down
+    sig_lsp_down = Signal(str)
+
     def __init__(self, parent,
                  server_settings={},
                  folder=getcwd_or_home(),
@@ -78,6 +82,7 @@ def __init__(self, parent,
         self.zmq_in_port = None
         self.zmq_out_port = None
         self.transport_client = None
+        self.lsp_server = None
         self.notifier = None
         self.language = language
 
@@ -135,6 +140,7 @@ def __init__(self, parent,
         self.server_args += [server_settings['cmd']]
         if len(server_args) > 0:
             self.server_args += server_args.split(' ')
+        self.server_unresponsive = False
 
         self.transport_args += transport_args.split(' ')
         self.transport_args += ['--folder', folder]
@@ -144,6 +150,7 @@ def __init__(self, parent,
         else:
             self.transport_args += ['--stdio-server']
             self.external_server = True
+        self.transport_unresponsive = False
 
     def start(self):
         self.zmq_out_socket = self.context.socket(zmq.PAIR)
@@ -274,6 +281,25 @@ def stop(self):
             self.lsp_server.kill()
 
     def send(self, method, params, kind):
+        # Detect when the transport layer is down to show a message
+        # to our users about it.
+        if (self.transport_client is not None and
+                self.transport_client.poll() is not None):
+            logger.debug(
+                "Transport layer for {} is down!!".format(self.language))
+            if not self.transport_unresponsive:
+                self.transport_unresponsive = True
+                self.sig_lsp_down.emit(self.language)
+            return
+
+        if (self.lsp_server is not None and
+                self.lsp_server.poll() is not None):
+            logger.debug("LSP server for {} is down!!".format(self.language))
+            if not self.server_unresponsive:
+                self.server_unresponsive = True
+                self.sig_lsp_down.emit(self.language)
+            return
+
         if ClientConstants.CANCEL in params:
             return
         _id = self.request_seq
diff --git a/spyder/plugins/completion/languageserver/plugin.py b/spyder/plugins/completion/languageserver/plugin.py
--- a/spyder/plugins/completion/languageserver/plugin.py
+++ b/spyder/plugins/completion/languageserver/plugin.py
@@ -153,6 +153,23 @@ def report_no_external_server(self, host, port, language):
                                               language=language.capitalize())
         )
 
+    @Slot(str)
+    def report_lsp_down(self, language):
+        """
+        Report that either the transport layer or the LSP server are
+        down.
+        """
+        QMessageBox.critical(
+            self.main,
+            _("Error"),
+            _("Completion and linting in the editor for {language} files "
+              "will not work during the current session, or stopped working."
+              "<br><br>"
+              "To fix this, please verify that your firewall or antivirus "
+              "allows Python processes to open ports in your system, or "
+              "restart Spyder.").format(language=language.capitalize())
+        )
+
     def start_client(self, language):
         """Start an LSP client for a given language."""
         started = False
@@ -206,6 +223,7 @@ def register_client_instance(self, instance):
                 self.update_configuration)
             self.main.sig_main_interpreter_changed.connect(
                 self.update_configuration)
+            instance.sig_lsp_down.connect(self.report_lsp_down)
             if self.main.editor:
                 instance.sig_initialize.connect(
                     self.main.editor.register_completion_server_settings)


Test patch: