Open jansopousek opened 7 months ago
Which Python version are you using?
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
This should fix it on the prompt_toolkit side: https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1810
This should fix it on IPython's side: https://github.com/ipython/ipython/pull/14241
Both fixes have to be published.
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.
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.
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.
This should fix it on the prompt_toolkit side: #1810
This and https://github.com/prompt-toolkit/python-prompt-toolkit/commit/8c601936b11d91388edc653df80aa34bd9cb1606 does not fix it for radian.
Cross reference: https://github.com/randy3k/radian/issues/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.
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:
The plot window is opened but frozen, the qt app is not properly started