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 when running code in the console #20381

Closed
6 of 10 tasks
raphaelquast opened this issue Jan 16, 2023 · 33 comments
Closed
6 of 10 tasks

ZMQError when running code in the console #20381

raphaelquast opened this issue Jan 16, 2023 · 33 comments

Comments

@raphaelquast
Copy link

raphaelquast commented Jan 16, 2023

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

This is not really a problem so far since all is working as expected, but since this showed up on multiple
PCs where I did a fresh miniconda / spyder install, I thought I'll ask whats going on here...

What steps reproduce the problem?

  1. install fresh miniconda
  2. conda install -c conda-forge spyder
  3. start spyder

What is the expected output? What do you see instead?

I'd expect spyder to start without any issues/warnings... however,
when I start spyder, the following shows up:

fromIccProfile: failed minimal tag size sanity
...\envs\rt1\lib\site-packages\jupyter_client\threaded.py:73: RuntimeWarning: ZMQStream only supports the base zmq.Socket class.

                Use zmq.Socket(shadow=other_socket)
                or `ctx.socket(zmq.DEALER, socket_class=zmq.Socket)`
                to create a base zmq.Socket object,
                no matter what other kind of socket your Context creates.

  self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)

Versions

  • Spyder version: 5.4.1
  • Python version: 3.9.15
  • Qt version: 5.15.6
  • PyQt version: 5.15.7
  • Operating System name/version: Windows 10

Dependencies

[click to show dependency list... ALL OK !]
# Mandatory:
atomicwrites >=1.2.0          :  1.4.1 (OK)
chardet >=2.0.0               :  5.1.0 (OK)
cloudpickle >=0.5.0           :  2.2.0 (OK)
cookiecutter >=1.6.0          :  2.1.1 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.0.2 (OK)
IPython >=7.31.1;<9.0.0       :  8.8.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.2 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.17.3 (OK)
keyring >=17.0.0              :  23.13.1 (OK)
nbconvert >=4.0               :  7.2.7 (OK)
numpydoc >=0.6.0              :  1.5.0 (OK)
paramiko >=2.4.0              :  2.12.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.4 (OK)
pygments >=2.0                :  2.14.0 (OK)
pylint >=2.5.0;<3.0           :  2.15.10 (OK)
pylint_venv >=2.1.1           :  2.3.0 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.7.0;<1.8.0          :  1.7.0 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.3 (OK)
qstylizer >=0.2.2             :  0.2.2 (OK)
qtawesome >=1.2.1             :  1.2.2 (OK)
qtconsole >=5.4.0;<5.5.0      :  5.4.0 (OK)
qtpy >=2.1.0                  :  2.3.0 (OK)
rtree >=0.9.7                 :  1.0.1 (OK)
setuptools >=49.6.0           :  65.6.3 (OK)
sphinx >=0.6.6                :  6.1.3 (OK)
spyder_kernels >=2.4.1;<2.5.0 :  2.4.1 (OK)
textdistance >=4.2.0          :  4.5.0 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.2.1 (OK)
zmq >=22.1.0                  :  25.0.0 (OK)

# Optional:
cython >=0.21                 :  0.29.33 (OK)
matplotlib >=3.0.0            :  3.6.2 (OK)
numpy >=1.7                   :  1.24.1 (OK)
pandas >=1.1.1                :  1.5.2 (OK)
scipy >=0.17.0                :  1.10.0 (OK)
sympy >=0.7.3                 :  None (OK)
@dalthviz
Copy link
Member

dalthviz commented Jan 16, 2023

Hi @raphaelquast thank you for the feedback! After Pyzmq released v25 we have had a related issue with Pyzmq (#20359) which was fixed over jupyter-client at PR jupyter/jupyter_client#914

What do you think @ccordoba12 ? This is something that should be fixed over jupyter-client too, right?

@raphaelquast
Copy link
Author

@dalthviz thanks for the quick response!

By the way... Now that I've been working a bit with the fresh spyder installation
I've also randomly encountered the following internal errors which are quite annoying and most probably related...
(maybe the traceback helps pinpointing the issue)

  File "...\envs\rt1\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "...\envs\rt1\lib\site-packages\tornado\platform\asyncio.py", line 647, in _handle_select
    self._handle_event(r, self._readers)
  File "...\envs\rt1\lib\site-packages\tornado\platform\asyncio.py", line 661, in _handle_event
    callback()
  File "...\envs\rt1\lib\site-packages\tornado\platform\asyncio.py", line 206, in _handle_events
    handler_func(fileobj, events)
  File "...\envs\rt1\lib\site-packages\zmq\eventloop\zmqstream.py", line 614, in _handle_events
    zmq_events = self.socket.EVENTS
  File "...\envs\rt1\lib\site-packages\zmq\sugar\attrsettr.py", line 56, in __getattr__
    return self._get_attr_opt(upper_key, opt)
  File "...\envs\rt1\lib\site-packages\zmq\sugar\attrsettr.py", line 68, in _get_attr_opt
    return self.get(opt)
  File "zmq/backend/cython/socket.pyx", line 512, in zmq.backend.cython.socket.Socket.get
  File "zmq/backend/cython/socket.pyx", line 270, in zmq.backend.cython.socket._getsockopt
  File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Unknown error

(... and just to take away the question... I'm already using jupyter_client 7.4.9 )

@dalthviz dalthviz added this to the v5.4.2 milestone Jan 16, 2023
@dalthviz
Copy link
Member

dalthviz commented Jan 16, 2023

Thanks for the extra info and new tracebacks! I think we should take care of those internal errors too for Spyder 4.5.2 (fixes that most probably need changes over jupyter-client). What do you think @ccordoba12 ?

@ccordoba12
Copy link
Member

when I start spyder, the following shows up:

Use zmq.Socket(shadow=other_socket)
or `ctx.socket(zmq.DEALER, socket_class=zmq.Socket)`
to create a base zmq.Socket object,
no matter what other kind of socket your Context creates.

That's just a warning and I think it'll be fixed in Jupyter-client 8. So there's nothing we can do about it for now.

By the way... Now that I've been working a bit with the fresh spyder installation
I've also randomly encountered the following internal errors which are quite annoying and most probably related...

@raphaelquast, you have to give us a reproducible code example to test it in our side and see how we could fix it. So far, no one else has reported that kind of problems, so we can't be sure if they are related to PyZMQ 25.

@raphaelquast
Copy link
Author

@ccordoba12 thanks for the response!

I know that the initial message is a warning but the internal errors I'm encountering also cause the console to become irresponsive (including quite strange behaviors such as the fact that matplotlib qt popup-plots remain open even if the parent spyder console is closed...).

I'll do a completely fresh setup as soon as possible and report back if the issues persist!
(so far I haven't been able to find a reproducible set of steps that cause the issue... it just happens after a certain amount of time without any obvious reason)

@raphaelquast
Copy link
Author

raphaelquast commented Feb 2, 2023

@ccordoba12
OK, I just did a fresh install of the environment (after conda update conda) and after ~10 minutes I ran into the very same issue again...

🐞 traceback
Exception in callback AddThreadSelectorEventLoop._handle_select([7992], [])
handle: <Handle AddThreadSelectorEventLoop._handle_select([7992], [])>
Traceback (most recent call last):
  File "D:\miniconda_NEW\envs\work\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "D:\miniconda_NEW\envs\work\lib\site-packages\tornado\platform\asyncio.py", line 647, in _handle_select
    self._handle_event(r, self._readers)
  File "D:\miniconda_NEW\envs\work\lib\site-packages\tornado\platform\asyncio.py", line 661, in _handle_event
    callback()
  File "D:\miniconda_NEW\envs\work\lib\site-packages\tornado\platform\asyncio.py", line 206, in _handle_events
    handler_func(fileobj, events)
  File "D:\miniconda_NEW\envs\work\lib\site-packages\zmq\eventloop\zmqstream.py", line 614, in _handle_events
    zmq_events = self.socket.EVENTS
  File "D:\miniconda_NEW\envs\work\lib\site-packages\zmq\sugar\attrsettr.py", line 56, in __getattr__
    return self._get_attr_opt(upper_key, opt)
  File "D:\miniconda_NEW\envs\work\lib\site-packages\zmq\sugar\attrsettr.py", line 68, in _get_attr_opt
    return self.get(opt)
  File "zmq/backend/cython/socket.pyx", line 512, in zmq.backend.cython.socket.Socket.get
  File "zmq/backend/cython/socket.pyx", line 270, in zmq.backend.cython.socket._getsockopt
  File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Unknown error

The commands I use to create the env is:

conda install -n base conda-libmamba-solver
conda config --set solver libmamba
conda create -n "work" -c conda-forge python=3.9 eomaps spyder matplotlib xarray rioxarray datashader

(first 2 lines only switch the conda-solver to libmamba as described here (I've used mamba a lot before without ever having any issues so I don't think this really connected... just to make this fully reproducible)

From my side there is absolutely no indication why this is happening... I'm happy to test suggestions!

@ccordoba12
Copy link
Member

Ok, please downgrade to PyZMQ 24 and try again:

conda activate work
conda install -c conda-forge pyzmq=24
spyder

@raphaelquast
Copy link
Author

@ccordoba12
Thanks for the quick response!

Yep, that did the trick just fine, all issues and warnings are now gone and spyder runs as nice and smooth it used to!

@raphaelquast
Copy link
Author

raphaelquast commented Feb 6, 2023

Hey @ccordoba12 , sorry for having to revert my previous statement...

While spyder is no longer showing any issues when using pyzmq=24, it seems that reverting the pyzmq
version causes some silent issues with the autocompletion in spyders ipython-console...

To be more precise: Somehow it is no longer possible to autocomplete beyond base-classes and functions...
Here's an example trying to autocomplete attributes of np.ndarray:

[click to show] plain Ipython console (working just fine)

spyder_ipython_autocomplete

[click to show] spyder console (no more autocompletion?)

spyder_spyderconsole_autocomplete

Do you know what's going on here or any temporary fix so that I can get autocompletion back?
(e.g. do you think reverting to a specific spyder-version could help for now?)

@raphaelquast
Copy link
Author

raphaelquast commented Feb 8, 2023

... just another update with my latest findings (since I really like to get my completions back somehow and at the moment I'm not sure how to even quick-fix this)

It seems that auto completion works if I assign the objects to names, e.g.:

  • if I do np.ndarray. <press TAB> no completions show
  • if I do x = np.ndarray and then x. <press TAB completions show as expected

This procedure works at arbitrary levels (e.g. as long as I always assign a name to the object I want to autocomplete)

Also... autocompletion in the editor-pane works (as long as it's not about attributes added at runtime)... so its really just the console that somehow stopped working

@dalthviz
Copy link
Member

dalthviz commented Feb 8, 2023

Could it be that the constraint update done to support IPython 8.x is the one causing the console completion failures for you @raphaelquast ? What happens with the completion in QtConsole? And what happens if you downgrade IPython to the latest 7.x version in your env where Spyder is installed?

@raphaelquast
Copy link
Author

raphaelquast commented Feb 9, 2023

Hey @dalthviz
Thanks for the response!

First, I tried completions in a jupyter qtconsole (with IPython 8.9.0) and everything works fine there.
(e.g. completions show up as expected)

Then I downgraded to IPython 7.33.0, and you were right! Now completions show up in the spyder console as expected again!

Finally I re-installed pyzmq 25.0 to see if the initial issues persist when using IPython 7.33.0.
Unfortunately the pyzmq warnings remain so I the 2 issues (autocompleting and the pyzmq warnings/errors) I'm facing might not be related. (also this pyqt error shows up now at startup: QTextCursor::setPosition: Position '-1' out of range)


To sumarize:

  • using spyder 5.4.3 with pyzmq 24.0.1 and IPython 7.33.0 all works as expected
    • using IPython 8.9.0 causes autocompletion in the console to fail (beyond the first level of attributes)
    • using pyzmq 25.0 results in the initial warnings as described above and randomly occurring errors like an unresponsive console and matplotlib qt popup plots that remain open even after the console is closed/restarted

@dalthviz
Copy link
Member

Note: probably we should create an issue for the completion not working properly on the console when using IPython 8.x

@callegar
Copy link

Is there a separate issue already for "using IPython 8 causes auto-completion in the console to fail (beyond the first level of attributes)"? Is it still worth opening?

@ccordoba12
Copy link
Member

Yes, there is: it's issue #20393.

@ccordoba12 ccordoba12 changed the title RuntimeWarning: ZMQStream only supports the base zmq.Socket class. ZMQError when running code in the console Mar 10, 2023
@ccordoba12
Copy link
Member

@minrk, sorry to ping you but several users have been reporting the error mentioned above since PyZMQ 25 was released, and all of them have reported that downgrading to version 24 fixes it.

Have you seen it before? And is there something we can do about it?

@minrk
Copy link
Contributor

minrk commented Mar 16, 2023

Never feel bad about pinging me on pyzmq issues! I'll look into it now.

@minrk
Copy link
Contributor

minrk commented Mar 16, 2023

I believe I know the general idea of what's happening. Spyder's debug logs helped, because they show that it follows context.destroy:

2023-03-16 10:01:08,405 [DEBUG] [traitlets] -> Destroying zmq context for <qtconsole.client.QtKernelClient object at 0x2e286a950>
2023-03-16 10:01:08,405 [DEBUG] [traitlets] -> Destroying zmq context for <qtconsole.client.QtKernelClient object at 0x290ba9510>
2023-03-16 10:01:08,406 [DEBUG] [traitlets] -> Destroying zmq context for <qtconsole.client.QtKernelClient object at 0x2fd5d8af0>
2023-03-16 10:01:08,406 [ERROR] [asyncio] -> Exception in callback BaseAsyncIOLoop._handle_events(342, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(342, 1)>
Traceback (most recent call last):
  File "/Users/minrk/conda/envs/spyder/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/minrk/conda/envs/spyder/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 206, in _handle_events
    handler_func(fileobj, events)
  File "/Users/minrk/conda/envs/spyder/lib/python3.10/site-packages/zmq/eventloop/zmqstream.py", line 614, in _handle_events
    zmq_events = self.socket.EVENTS
  File "/Users/minrk/conda/envs/spyder/lib/python3.10/site-packages/zmq/sugar/attrsettr.py", line 55, in __getattr__
    return self._get_attr_opt(upper_key, opt)
  File "/Users/minrk/conda/envs/spyder/lib/python3.10/site-packages/zmq/sugar/attrsettr.py", line 67, in _get_attr_opt
    return self.get(opt)
  File "zmq/backend/cython/socket.pyx", line 512, in zmq.backend.cython.socket.Socket.get
  File "zmq/backend/cython/socket.pyx", line 270, in zmq.backend.cython.socket._getsockopt
  File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Socket operation on non-socket

pyzmq 25 is relevant because if ZMQStream is given an unsupported socket type (as jupyter-client 7 does, hence the warning at ZMQStream creation time), it uses a shadow socket to avoid making callbacks with the wrong types. The one downside of shadow sockets (a second Python object pointing to the same underlying zmq socket) is that one can be closed without the other noticing. When that happens, the next zmq API call on the socket may fail with a ZMQError. It should generally be ENOTSOCK (as above), though it's a bit worrying that there's one report of zmq.error.ZMQError: Unknown error.

Ultimately, what's happening is that a libzmq socket is being closed while a ZMQStream is still using it. This may be due to a threading race condition in jupyter-client.

I believe the right fix for this is in pyzmq to add a guard on self.socket.EVENTS, understanding that the socket may have been closed by something else. It's possible that jupyter-client should also have a fix, but if jupyter-client 8 doesn't have this problem, it may not be worth pursuing.

@ccordoba12
Copy link
Member

Thanks for your help @minrk! How did you manage to generate the error (I've been unable to)? That way I can patch both PyZMQ and Jupyter-client with your changes and tell you if that fixes this problem on my side.

@minrk
Copy link
Contributor

minrk commented Mar 17, 2023

I opened zeromq/pyzmq#1848 which should fix the issue in pyzmq (handling socket being closed somewhere else) and jupyter/jupyter_client#936 which should fix it in jupyter-client (explicitly close the stream before closing the socket).

I don't really understand where problematic behavior would likely come from, though, because if I've understood the failure correctly, this should only be a log of unhandled error and moving on. It's possible there's a second, related bug I'm still missing. It also may be in the failure to close the stream, which leaves an event listener on the FD, which may be reclaimed by a future socket, but I really don't know about that.

How did you manage to generate the error (I've been unable to)?

I've actually struggled to reproduce the error. It's happened a couple of times, but I cannot provoke it reliably. Since it's a threadsafety issue, it's challenging. To provoke the issue above, I think you have to:

  1. deliver an event on a socket channel, which select in the background io thread notices in select, but has not had a chance to fire the callback
  2. close the channels for the client, which closes the socket, but does not get far enough to close the event loop for the io thread itself
  3. background thread fires the callback, on the now closed socket

This may be more likely to occur on Windows, where select occurs in yet another thread, increasing the time between event registration and event handling, on account of proactor only being a partial asyncio event loop implementation.

@ccordoba12
Copy link
Member

ccordoba12 commented Mar 17, 2023

and jupyter/jupyter_client#936 which should fix it in jupyter-client (explicitly close the stream before closing the socket).

Left a tiny review for you there.

This may be more likely to occur on Windows

Unfortunately, I don't have a recent Windows VM to test this. Besides, it seems the test you added in your PyZMQ PR works pretty much in the same way as the steps you described above, right? So, that looks good to me.

@raphaelquast
Copy link
Author

@ccordoba12 Not sure I can be much of help here on the programming side, but if you give some instructions on how to test the fixes, I'm happy to provide feedback if all works as expected on windows!

@minrk
Copy link
Contributor

minrk commented Mar 22, 2023

@raphaelquast if you upgrade to jupyter-client 8.1.0 and/or pyzmq 25.0.2, that should test whether the fixes are working.

@raphaelquast
Copy link
Author

raphaelquast commented Mar 22, 2023

Thanks @minrk

I tried installing but mamba forces me to downgrade spyder, qtconsole etc. in the process...

[click to show] mamba downgrade summary
  Package                   Version  Build             Channel                 Size
-------------------------------------------------------------------------------------
  Upgrade:
-------------------------------------------------------------------------------------

  - jupyter_client            7.4.9  pyhd8ed1ab_0      conda-forge
  + jupyter_client            8.1.0  pyhd8ed1ab_0      conda-forge/noarch     104kB
  - pyzmq                    24.0.1  py39hea35a22_1    conda-forge
  + pyzmq                    25.0.2  py39hea35a22_0    conda-forge/win-64     401kB

  Downgrade:
-------------------------------------------------------------------------------------

  - flake8                    6.0.0  pyhd8ed1ab_0      conda-forge
  + flake8                    4.0.1  pyhd8ed1ab_2      conda-forge/noarch      85kB
  - mccabe                    0.7.0  pyhd8ed1ab_0      conda-forge
  + mccabe                    0.6.1  py_1              conda-forge/noarch       9kB
  - pycodestyle              2.10.0  pyhd8ed1ab_0      conda-forge
  + pycodestyle               2.8.0  pyhd8ed1ab_0      conda-forge/noarch      40kB
  - pyflakes                  3.0.1  pyhd8ed1ab_0      conda-forge
  + pyflakes                  2.4.0  pyhd8ed1ab_0      conda-forge/noarch      59kB
  - python-lsp-server         1.7.1  hd8ed1ab_0        conda-forge
  + python-lsp-server         1.5.0  hd8ed1ab_1        conda-forge/noarch       5kB
  - python-lsp-server-base    1.7.1  pyhd8ed1ab_0      conda-forge
  + python-lsp-server-base    1.5.0  pyhd8ed1ab_1      conda-forge/noarch      47kB
  - qtconsole                 5.4.0  pyhd8ed1ab_0      conda-forge
  + qtconsole                 5.3.2  pyhd8ed1ab_0      conda-forge/noarch       6kB
  - qtconsole-base            5.4.0  pyha770c72_0      conda-forge
  + qtconsole-base            5.3.2  pyha770c72_0      conda-forge/noarch      93kB
  - spyder                    5.4.2  py39hcbf5309_0    conda-forge
  + spyder                    5.3.2  py39hcbf5309_0    conda-forge/win-64      13MB
  - spyder-kernels            2.4.2  win_pyhd8ed1ab_0  conda-forge
  + spyder-kernels            2.3.2  py39hcbf5309_0    conda-forge/win-64     111kB

  Summary:

  Upgrade: 2 packages
  Downgrade: 10 packages

  Total download: 14MB

running conda create -n test -c conda-forge jupyter_client=8.1.0 pyzmq=25.0.2 spyder=5.4.2 gives the following error:

LibMambaUnsatisfiableError: Encountered problems while solving:
  - nothing provides __unix needed by spyder-kernels-2.4.2-unix_pyhd8ed1ab_0

any idea why it searches for a unix version on windows?

@ccordoba12
Copy link
Member

@raphaelquast, the problem is Spyder-kernels doesn't support Jupyter-client 8 yet. But we'll fix that in our next version (2.4.3) to be released alongside Spyder 5.4.3.

@raphaelquast
Copy link
Author

@ccordoba12 OK, thanks for the clarification! Feel free to ping me if you want someone to check if this issue persists on windows once Spyder 5.4.3 is released!

@minrk
Copy link
Contributor

minrk commented Mar 22, 2023

You should be able to test just pyzmq 25.0.2, which I think will be sufficient.

@raphaelquast
Copy link
Author

raphaelquast commented Mar 23, 2023

I tried working a while with pyzmq 25.0.2.
The initial zmq base-socket warning shows up again but so far I didn't experience any issues regarding non-responsive ipython terminals or qt popups. I'll keep using the latest pyzmq version and report back here if I encounter problems!

Thanks for taking care of this so quickly!


However, in the process I also tested upgrading to IPython 8.11.0 in the hope that it fixes autocompletion as indicated by #20393 but unfortunately I have to report that on windows autocompletion still only works at the first level, e.g.:

  • np. <tab> works but np.ndarray. <tab> does not
    • however x=np.ndarray followed by x. <tab> works again as expected
  • (all works well with IPython 7.33.0 and pyzmq 25.0.2)

Is there an issue addressing this behavior? (#20393 seems to be a different problem)

@raphaelquast
Copy link
Author

raphaelquast commented Mar 24, 2023

Hey @minrk

sorry to revert back on my previous comment... but unfortunately pyzmq 25.0.2 alone does not solve the issue!
It just took a while until it showed up again...

Now the following happens:

  • The error appears again without any obvious reason with the (new) error message below
  • Once the error happens, each new input to the console (even something like 1+1) results in the same error again (and the command is not executed)
Exception in callback functools.partial(<bound method ThreadedZMQSocketChannel._flush of <qtconsole.client.QtZMQSocketChannel object at 0x0000020B619B4DC0>>)
Traceback (most recent call last):
  File "D:\miniconda_NEW\envs\work\lib\site-packages\tornado\ioloop.py", line 740, in _run_callback
    ret = callback()
  File "D:\miniconda_NEW\envs\work\lib\site-packages\jupyter_client\threaded.py", line 183, in _flush
    self.stream.flush()
  File "D:\miniconda_NEW\envs\work\lib\site-packages\zmq\eventloop\zmqstream.py", line 483, in flush
    self._check_closed()
  File "D:\miniconda_NEW\envs\work\lib\site-packages\zmq\eventloop\zmqstream.py", line 685, in _check_closed
    raise OSError("Stream is closed")
OSError: Stream is closed

@ccordoba12
Copy link
Member

ccordoba12 commented Mar 29, 2023

sorry to revert back on my previous comment... but unfortunately pyzmq 25.0.2 alone does not solve the issue!
It just took a while until it showed up again...

That shows that we also require the Jupyter-client fix @minrk did in its version 8.1.0 release to fully solve this problem. So, I added support for it to Spyder-kernels, which will be part of its 2.4.3 version.

However, in the process I also tested upgrading to IPython 8.11.0 in the hope that it fixes autocompletion
Is there an issue addressing this behavior? (#20393 seems to be a different problem)

That's not a bug in Spyder. It's actually a bug in IPython, so I'll report it there. A workaround for now is to go to

Tools > Preferences > IPython console > Advanced settings

and enable the option called

Use Jedi completion in the IPython console

However, you need to be aware that that could make the console slower when inspecting big dataframes or other large variables. That's why it's disabled by default.

@minrk
Copy link
Contributor

minrk commented Mar 29, 2023

I think the flush might be a bug in spyder or qtconsole (it might also be a bug in jupyter-client), because flush is called here in qtconsole or here in spyder without checking if the channel has been closed. That should result in an IOError (just like calling flush() on a closed file), though I still wouldn't expect it to result in hangs. I'm not sure, though.

Because of the async nature of how jupyter-client schedules this, there is a chance it's an issue in jupyter-client as well.

The error doesn't propagate to the caller because of how it's scheduled on the IO Thread in jupyter-client, but I will fix that shortly.

@ccordoba12
Copy link
Member

ccordoba12 commented Mar 29, 2023

Thanks for your continued help @minrk! I must admit that I only skimmed the traceback above and since I saw it came from Jupyter-client, I assumed it was fixed by your jupyter/jupyter_client#936 PR.

I think the flush might be a bug in spyder or qtconsole (it might also be a bug in jupyter-client), because flush is called here in qtconsole or here in spyder without checking if the channel has been closed.

Ok, thanks for pointing that out. I'll add a check before calling flush in those places.

@ccordoba12
Copy link
Member

To be more precise: Somehow it is no longer possible to autocomplete beyond base-classes and functions...
Here's an example trying to autocomplete attributes of np.ndarray

@raphaelquast, this should be fixed in IPython 8.13 thanks to the PR I opened for it: ipython/ipython#14029.

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

5 participants