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

3.0.40 causing interactive gui to not work from ipython console #1809

Open
jansopousek opened this issue Nov 11, 2023 · 7 comments
Open

3.0.40 causing interactive gui to not work from ipython console #1809

jansopousek opened this issue Nov 11, 2023 · 7 comments

Comments

@jansopousek
Copy link

When starting the qt apps from ipython console, those apps are not working properly. This can be reproduced by following code in the ipython console:

import matplotlib.pyplot as plt

%matplotlib qt6

plt.plot([0,1])

The plot window is opened but frozen, the qt app is not properly started

@jonathanslenders
Copy link
Member

Which Python version are you using?

@jonathanslenders
Copy link
Member

Most likely this is caused by some changes that were done because asyncio.get_event_loop() is deprecated now. I don't remember when exactly this was done, but there were a few attempts at least. IPython installs an event loop which contains the inputhook for QT and prompt_toolkit is supposed to pick it up using get_event_loop(). However, this is deprecated, and get_running_loop() won't return a loop when it's not running, so on Python 3.10, 3.11 and 3.12, we create a new loop without the input hook, which causes the QT application to freeze.

We have to rethink this a bit. I think prompt_toolkit.application.Application.run() (and prompt_toolkit.prompt.PromptSession.prompt() should take an inputhook as an argument that we install ourselves in the application that we run.)

I'll see if I can come up with an PR this weekend. @jansopousek: Would you be willing to test, if I push an PR for both prompt_toolkit and IPython?

cc: @Carreau

@jonathanslenders
Copy link
Member

jonathanslenders commented Nov 11, 2023

This should fix it on the prompt_toolkit side: #1810

This should fix it on IPython's side: ipython/ipython#14241

Both fixes have to be published.

@jansopousek
Copy link
Author

We are using python 3.11. Thanks for fixing it up. It is not that straightforward for me to test those, since I don't have any of those packages installed from source. But by the code which I provided it should be pretty easy to replicate.

@jonathanslenders
Copy link
Member

As a workaround I released prompt_toolkit 3.0.41 earlier today, which detects whether it's being called from IPython and adjusts accordingly to avoid this bug. A fix on IPython's side should follow soon.

@molinav
Copy link

molinav commented Nov 19, 2023

I can confirm this issue also on Windows 11 using Python 3.11.4, IPython 8.17.2, matplotlib 3.7.4, and both Tk (builtin) or PyQt5 5.15.10. A simple interactive IPython session with plt.figure() shows a plotting window that does not react and hangs. The error occurs to me for both prompt-toolkit versions 3.0.41 and 3.0.40. If I downgrade to 3.0.39, IPython works again normally.

Carreau added a commit to ipython/ipython that referenced this issue Nov 20, 2023
…sion.run(). (#14241)

See: prompt-toolkit/python-prompt-toolkit#1809

To summarize:
- In prompt_toolkit, some changes were done to get rid of a deprecation
warning related to the usage of `set_event_loop()` on Python 3.12. It
looks like IPython did had a workaround for the deprecation warning, but
Xonsh for instance did not. Now, the code that was fixed in
prompt_toolkit breaks input hooks in IPython.
- The right thing to do would be to accept the input hook as an argument
in prompt_toolkit, which is what this PR does:
prompt-toolkit/python-prompt-toolkit#1810
- For IPython, we have to do a similar change to pass it as an argument
(this PR).

It's not well tested (I'm not using IPython with inputhooks myself). I'm
also not very familiar myself with IPython's code base.

I think it requires some coordination. I'm not sure if there's a way to
be backward compatible. I guess if I push a new prompt_toolkit version
with the fix on my side, nothing will break, but input hooks will for
sure not work on any Python version until this is merged.

We should probably set the minimum prompt_toolkit version after merging
this.
@benz0li
Copy link

benz0li commented Nov 28, 2023

This should fix it on the prompt_toolkit side: #1810

This and 8c60193 does not fix it for radian.

Cross reference: randy3k/radian#446

This should fix it on IPython's side: ipython/ipython#14241

@randy3k, please please consult with @jonathanslenders on what needs to be changed on radian's side.

Both fixes have to be published.

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

No branches or pull requests

4 participants