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

Spyder 5.2.1 stuck connecting to kernel when using the Tk backend on Windows #17024

Closed
trierweiler opened this issue Dec 15, 2021 · 12 comments
Closed

Comments

@trierweiler
Copy link

Description

What steps will reproduce the problem?

Using Win10.
Downloaded Spyder 5.2.1 from spyder-ide.org

  1. Create a virtualenv with Python 3.10
  2. pip install spyder-kernels==2.2.*
  3. Change default environment to the new one
  4. Launch Spyder and IPython console runs nicely
  5. pip install matplolib in the environment
  6. launch new console
  7. Connecting to kernel ... (forever)

Versions

  • Spyder version: 5.2.1
  • 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           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree                  :  None (OK)
IPython >=7.6.0               :  7.30.1 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.8.9 (OK)
jsonschema >=3.2.0            :  4.2.1 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  6.3.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.8.1 (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.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0                :  2.12.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.3.2;<1.4.0          :  1.3.3 (OK)
pylsp_black >=1.0.0           :  1.0.1 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.1.1 (OK)
qtconsole >=5.2.1;<5.3.0      :  5.2.2 (OK)
qtpy >=1.5.0                  :  1.11.3 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  59.6.0 (OK)
sphinx >=0.6.6                :  4.3.1 (OK)
spyder_kernels >=2.2.0;<2.3.0 :  2.2.0 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog                      :  2.1.6 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  0.29.25 (OK)
matplotlib >=2.0.0            :  3.5.1 (OK)
numpy >=1.7                   :  1.19.3 (OK)
pandas >=1.1.1                :  1.3.5 (OK)
scipy >=0.17.0                :  1.7.3 (OK)
sympy >=0.7.3                 :  1.9 (OK)
@trierweiler
Copy link
Author

The IPython console launches if I unninstall matplotlib.

@ccordoba12
Copy link
Member

Hey @trierweiler, thanks for opening this issue! Are you also seeing the error you reported in #16765 (comment)?

@ccordoba12
Copy link
Member

Please also describe the steps you followed to

Create a virtualenv with Python 3.10

@rhkarls
Copy link
Contributor

rhkarls commented Dec 15, 2021

I observed something similar (see spyder-ide/spyder-kernels#347). Having the backend set to "Automatic" and not having pyqt5 installed, or choosing "Tkinter" as backend causes the console to be stuck on "Connecting to kernel...". @trierweiler Have you tried changing backend under Tools>Preferences>IPython console>Graphics and starting a new console, in case the behavior is similar?

@trierweiler
Copy link
Author

trierweiler commented Dec 15, 2021 via email

@impact27
Copy link
Contributor

impact27 commented Jan 3, 2022

Running "%matplotlib tk" in an ipykernel console results in:

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\eventloops.py:259: RuntimeWarning: coroutine 'Kernel.do_one_iteration' was never awaited
  self.func()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

So it is likely that the tk eventloop is broken in ipykernel since #632

@impact27
Copy link
Contributor

impact27 commented Jan 3, 2022

See: ipython/ipykernel#742

@ccordoba12
Copy link
Member

Thanks @impact27 for your help with this!

It seems the fix is relatively simple (just running synchronously the do_one_iteration coroutine). I'll try to take a look at it later today.

@impact27
Copy link
Contributor

impact27 commented Jan 3, 2022

Well you can't because then the loops would be nested. Unless you use https://github.com/erdewit/nest_asyncio. But that might be a hard sell for ipykernel. I think the entrire tk eventloop has to be rewritten. THe solutions I see are to:

  • Force ipykernel<6
  • Disable tk backend

@ccordoba12
Copy link
Member

ccordoba12 commented Jan 3, 2022

nest_asyncio is already a dependency of jupyter_client, so we can proceed with that solution:

https://github.com/jupyter/jupyter_client/blob/0eb492726cc279fdb3e2ff690cb62e8a69182d0d/jupyter_client/utils.py#L11-L29

I was thinking to use that run_sync function to fix the problem, but since you seem better acquainted with it, could you give me a hand to solve it?

@ccordoba12 ccordoba12 changed the title Spyder 5.2.1 connecting to kernel ... Spyder 5.2.1 connecting to kernel when using the Tk backend Jan 3, 2022
@impact27
Copy link
Contributor

impact27 commented Jan 3, 2022

I opened ipython/ipykernel#830

@ccordoba12
Copy link
Member

Thanks a lot @impact27!

@ccordoba12 ccordoba12 changed the title Spyder 5.2.1 connecting to kernel when using the Tk backend Spyder 5.2.1 stuck connecting to kernel when using the Tk backend Jan 3, 2022
@ccordoba12 ccordoba12 changed the title Spyder 5.2.1 stuck connecting to kernel when using the Tk backend Spyder 5.2.1 stuck connecting to kernel when using the Tk backend on Windows Jan 8, 2022
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

4 participants