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

ZMQError: Address already in use when restarting the kernel #14739

Closed
HBolandi opened this issue Feb 12, 2021 · 15 comments
Closed

ZMQError: Address already in use when restarting the kernel #14739

HBolandi opened this issue Feb 12, 2021 · 15 comments

Comments

@HBolandi
Copy link

HBolandi commented Feb 12, 2021

I have installed Anaconda (python 3.7) in my ubuntu 20.04 system and I am using Spyder. I am running CNN and while runs for some part of data it's fine but when I run it for entire data (more that 100000) I am getting the following error:

an error occurred while starting the kernel

Steps that reproduce the problem:

  1. run the code
  2. running for about 20 minutes
  3. Spyder tries to restart the kernel
  4. error raised
Traceback (most recent call last):
File "/home/exx/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/exx/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/exx/anaconda3/lib/python3.7/site‑packages/spyder_kernels/console/__main__.py", line 23, in 
start.main()
File "/home/exx/anaconda3/lib/python3.7/site‑packages/spyder_kernels/console/start.py", line 284, in main
kernel.initialize()
File "/home/exx/anaconda3/lib/python3.7/site‑packages/traitlets/config/application.py", line 87, in inner
return method(app, *args, **kwargs)
File "/home/exx/anaconda3/lib/python3.7/site‑packages/ipykernel/kernelapp.py", line 567, in initialize
self.init_sockets()
File "/home/exx/anaconda3/lib/python3.7/site‑packages/ipykernel/kernelapp.py", line 271, in init_sockets
self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
File "/home/exx/anaconda3/lib/python3.7/site‑packages/ipykernel/kernelapp.py", line 218, in _bind_socket
return self._try_bind_socket(s, port)
File "/home/exx/anaconda3/lib/python3.7/site‑packages/ipykernel/kernelapp.py", line 194, in _try_bind_socket
s.bind("tcp://%s:%i" % (self.ip, port))
File "/home/exx/anaconda3/lib/python3.7/site‑packages/zmq/sugar/socket.py", line 173, in bind
super().bind(addr)
File "zmq/backend/cython/socket.pyx", line 542, in zmq.backend.cython.socket.Socket.bind
File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Address already in use

Versions:

  • Spyder 4.2.1:
  • Python 3.7.9:
  • Qt 5.15.2:
  • PyQt 5.15.2:
  • Linux/5.4.0.65-generic:
  • Ubuntu 20.04

Dependencies:

# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  4.0.0 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=7.6.0                 :  7.20.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
keyring >=17.0.0                :  22.0.1 (OK)
nbconvert >=4.0                 :  6.0.7 (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.8.0 (OK)
pygments >=2.0                  :  2.7.4 (OK)
pylint >=1.0                    :  2.6.0 (OK)
pyls >=0.36.2;<1.0.0            :  0.36.2 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.3.0             :  0.3.0 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.1 (OK)
qtconsole >=5.0.1               :  5.0.2 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
rtree >=0.8.3                   :  0.9.4 (OK)
setuptools >=39.0.0             :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                  :  3.4.3 (OK)
spyder_kernels >=1.10.1;<1.11.0 :  1.10.1 (OK)
textdistance >=4.2.0            :  4.2.1 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3               :  1.0.2 (OK)
xdg >=0.26                      :  0.27 (OK)
zmq >=17                        :  20.0.0 (OK)

# Optional:
cython >=0.21                   :  0.29.21 (OK)
matplotlib >=2.0.0              :  3.3.0 (OK)
numpy >=1.7                     :  1.19.2 (OK)
pandas >=1.1.1                  :  1.1.0 (NOK)
scipy >=0.17.0                  :  1.5.2 (OK)
sympy >=0.7.3                   :  1.6.1 (OK)
@juanis2112
Copy link
Contributor

Hi @HBolandi thanks for reporting this. I'll assign @CAM-Gerlach to take care of this one.

@CAM-Gerlach
Copy link
Member

Hello @HBolandi , sorry for the trouble. Its a little unclear to me if the restart was manually triggered by your action or simply happens on its own after your code is running for long enough, but the immediate cause of the error message appears to be that the previous kernel evidently hangs and doesn't free the ZMQ connection/port that Spyder uses to communicate it. This has been reported elsewhere with other Jupyter kernel clients, in various situations, but without a clear-cut solution.

Assuming you aren't manually interrupting or trying to restart the kernel, it seems likely there was either a serious problem with your code, or it ran out of memory/other resources. To determine if the error is due to something Spyder can directly control, can you run the same code in QtConsole and see if it happens again? You can open it from Anaconda Navigator or by typing jupyter qtconsole with your conda environment activated.

If it only happens in Spyder, can you share a minimal example of some code that will reproduce it, as well as any additional information on what you're trying to do and the circumstances in which it occurs? Thanks.

As for the error on reconnecting, you can either try re-opening a new console, or use kill/your task manager to terminate the offending process (which can be found via e.g. sudo netstat -ltnp on your Linix system).

I'm not sure if there's anything we can do about it on our end, but if so its pretty deep in the interaction between spyder_kernels, jupyter_client and pyzmq. @ccordoba12 @dalthviz , any insights there?

Hopefully this is helpful—let us know, thanks.

@HBolandi
Copy link
Author

Thanks for your response. The restart happened on its own after my code is running for long enough. As you mentioned it could be running out of memory/other resources since the code is working fine with less data. I will try to implement DDP in my code and will return back to you.

@CAM-Gerlach
Copy link
Member

Thanks for letting us know; we really appreciate it. Best of luck with that, and we look forward to hearing good news; if not, we can see if there's anything we can do on our end. Cheers.

@deMalmazet
Copy link

Hi, I'm having the same problem, without running any code, but just by starting Spyder and restarting the kernel. Opening a new console, or closing the current one solves it, However, I'm not sure if it's a good idea to open tens of consoles.
I noticed also that I get this error only when I run Spyder installed through the standalone installer. If I use Spyder installed from the Conda environment, I do not get this error. However, I get another annoying behaviour, which is that running a cell with ctrl + enter or ctrl + shift + enter, or running more than one line of code selected by pressing F9, results in the whole file being executed. I checked the preferences, and all the shortcuts keys are properly set.
Please let me know if you any insight on that.
Thank you

@CAM-Gerlach
Copy link
Member

Hey @deMalmazet , sorry you're running into this issue. Could you verify you get the exact same full traceback as above, and confirm what version of Spyder you are using with Anaconda and standalone, your operating system version, the Python and Spyder-Kernels version in the working environment you have selected by default (i.e. the one that starts when you open Spyder, which it sounds like you're experiencing an issue in), and whether you can reproduce the issue both using the internal default env as your working environment, and other Anaconda environments?

With regard to opening many consoles, you can open as many as you want in one session, though its probably good idea to keep it to between a half dozen to a dozen at any given time, given each runs in a seperate process that consumes a non-trivial amount of RAM.

Also, with regard to the file being run when you mean to just run the sell or line, you've confirmed this still occurs when you use the menu item or the toolbar button, right?

@deMalmazet
Copy link

Hi @CAM-Gerlach , Thank you for your prompt answer. I originally posted my issue here, with my specs (#14994). I'll copy them here:

Versions
Spyder version: 4.2.4
Python version: 3.7.9
Qt version: 5.12.10
PyQt5 version: 5.12.3
Operating System: Windows 10
Dependencies

Mandatory:

atomicwrites >=1.2.0 : 1.4.0 (OK)
chardet >=2.0.0 : 4.0.0 (OK)
cloudpickle >=0.5.0 : 1.6.0 (OK)
diff_match_patch >=20181111 : 20200713 (OK)
intervaltree : None (OK)
IPython >=7.6.0 : 7.21.0 (OK)
jedi =0.17.2 : 0.17.2 (OK)
jsonschema >=3.2.0 : 3.2.0 (OK)
keyring >=17.0.0 : 23.0.0 (OK)
nbconvert >=4.0 : 6.0.7 (OK)
numpydoc >=0.6.0 : 1.1.0 (OK)
paramiko >=2.4.0 : 2.7.2 (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.8.0 (OK)
pygments >=2.0 : 2.8.1 (OK)
pylint >=1.0 : 2.7.2 (OK)
pyls >=0.36.2;<1.0.0 : 0.36.2 (OK)
pyls_black >=0.4.6 : 0.4.6 (OK)
pyls_spyder >=0.3.2 : 0.3.2 (OK)
qdarkstyle >=2.8;<3.0 : 2.8.1 (OK)
qtawesome >=0.5.7 : 1.0.2 (OK)
qtconsole >=5.0.3 : 5.0.3 (OK)
qtpy >=1.5.0 : 1.9.0 (OK)
rtree >=0.8.3 : 0.9.4 (OK)
setuptools >=39.0.0 : 54.1.2 (OK)
sphinx >=0.6.6 : 3.5.2 (OK)
spyder_kernels >=1.10.2;<1.11.0 : 1.10.2 (OK)
textdistance >=4.2.0 : 4.2.1 (OK)
three_merge >=0.1.1 : 0.1.1 (OK)
watchdog : 1.0.2 (OK)
zmq >=17 : 22.0.3 (OK)

Optional:

cython >=0.21 : 0.29.22 (OK)
matplotlib >=2.0.0 : 3.3.4 (OK)
numpy >=1.7 : 1.19.3 (OK)
pandas >=1.1.1 : 1.2.3 (OK)
scipy >=0.17.0 : 1.6.1 (OK)
sympy >=0.7.3 : 1.7.1 (OK)

@deMalmazet
Copy link

deMalmazet commented Mar 25, 2021

Here is the traceback :

An error ocurred while starting the kernel

Traceback (most recent call last):
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\spyder_kernels\console_main.py", line 23, in
start.main()
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\spyder_kernels\console\start.py", line 284, in main
kernel.initialize()
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\traitlets\config\application.py", line 87, in inner
return method(app, *args, **kwargs)
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\ipykernel\kernelapp.py", line 567, in initialize
self.init_sockets()
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\ipykernel\kernelapp.py", line 271, in init_sockets
self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\ipykernel\kernelapp.py", line 218, in _bind_socket
return self._try_bind_socket(s, port)
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\ipykernel\kernelapp.py", line 194, in _try_bind_socket
s.bind("tcp://%s:%i" % (self.ip, port))
File "C:\Users\Daniel\anaconda3\envs\TrackPlat\lib\site‑packages\zmq\sugar\socket.py", line 172, in bind
super().bind(addr)
File "zmq/backend/cython/socket.pyx", line 540, in zmq.backend.cython.socket.Socket.bind
File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Address in use

@deMalmazet
Copy link

I am using the same default environment with the standalone version and with the Conda version, and also the same system.
When I start Spyder with Conda, I am using Spyder 4.2.3, Python 3.9.2 64-bit | Qt 5.12.9 | PyQt5 5.12.3 | Windows 10. This is what it says when I click "about Spyder"
I am using the same python interpreter with both, which is Python 3.9.2, and this is what is written in the Python console for both the standalone and Conda versions. However, on the standalone Spyder, when I click "about Spyder", it says Python 3.7.9, which is also what you see on the automatic git hub issue report above.

Also, I just tried with the standalone version 4.2.5, and the problem remains.

@deMalmazet
Copy link

With regard to the file being run when I mean to just run the sell or line, this seems to be working well now.

@ccordoba12 ccordoba12 changed the title Why I am getting this error: an error occurred while starting the kernel "ZMQError: Address already in use" when restarting the kernel Apr 24, 2021
@ccordoba12 ccordoba12 changed the title "ZMQError: Address already in use" when restarting the kernel ZMQError: Address already in use when restarting the kernel Apr 24, 2021
@ccordoba12
Copy link
Member

ccordoba12 commented Apr 30, 2021

@minrk, sorry to ping you out of the blue, but do you know why this happens in some cases?

It's only an issue when restarting kernels.

@cvergari
Copy link

cvergari commented May 7, 2021

Hi, I am having the same issue with Spyder 5.0.0. This occurs whenever I manually restart the kernel, even immediately after opening Spyder (I mean before running any code). The kernel restarts if I manually close the console, but the problem persists in the new console. I installed Spyder through conda, not standalone.

Traceback:
File "C:\Users\Claudio\miniconda3\envs\web\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Claudio\miniconda3\envs\web\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\spyder_kernels\console\__main__.py", line 23, in 
start.main()
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\spyder_kernels\console\start.py", line 284, in main
kernel.initialize()
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\traitlets\config\application.py", line 87, in inner
return method(app, *args, **kwargs)
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\ipykernel\kernelapp.py", line 567, in initialize
self.init_sockets()
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\ipykernel\kernelapp.py", line 271, in init_sockets
self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\ipykernel\kernelapp.py", line 218, in _bind_socket
return self._try_bind_socket(s, port)
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\ipykernel\kernelapp.py", line 194, in _try_bind_socket
s.bind("tcp://%s:%i" % (self.ip, port))
File "C:\Users\Claudio\miniconda3\envs\web\lib\site‑packages\zmq\sugar\socket.py", line 173, in bind
super().bind(addr)
File "zmq/backend/cython/socket.pyx", line 542, in zmq.backend.cython.socket.Socket.bind
File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Address in use
* Spyder version: 5.0.0
* Python version: 3.8.8
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Windows 10 

Claudio

@analyticssolvers
Copy link

  • Spyder version: 5.1.5 None
  • Python version: 3.9.7 64-bit
  • Qt version: 5.9.7
  • PyQt5 version: 5.9.2
  • Operating System: Windows 10

@ccordoba12
Copy link
Member

ccordoba12 commented Dec 23, 2021

According to the Jupyter team (we use the same architecture as them to run code), this is caused by slow to start kernels. It should be fixed in our latest version (5.2.1), when jupyter-client 7.1.0 is installed.

@ccordoba12
Copy link
Member

We'll fix this by requiring that version of jupyter-client explicitly in our next version (5.2.2), to be released in January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants