prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

[3.0.37] DeprecationWarning: There is no current event loop (from asyncio) #1750

Closed jdkirkwood closed 7 months ago

jdkirkwood commented 1 year ago

Hi,

233a818c15d935a8fda07cbb0d0102b7c1290337 in release 3.0.37 re-introduces asyncio.get_event_loop() which was deprecated and removed in a7759969891c54ea56abfa286524cc301eedaf05 earlier in the same release.

My Python 3.10 venv fails with prompt-toolkit==3.0.38, but a similar Python 3.8 venv is ok. Downgrading to prompt-toolkit==3.0.36 allows my Python 3.10 venv to run normally.

(#1726 starts with a different issue but has comments/links directly related to this issue).

2023-04-22 12:34:49,307 18523 WARNING xxx py.warnings: xxx/venv/lib/python3.10/site-packages/prompt_toolkit/application/application.py:955: DeprecationWarning: There is no current event loop
...
  File "zzz/shell.py", line 91, in ipython
    start_ipython(argv=[], user_ns=local_vars)
  File "xxx/venv/lib/python3.10/site-packages/IPython/__init__.py", line 124, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "xxx/venv/lib/python3.10/site-packages/traitlets/config/application.py", line 1043, in launch_instance
    app.start()
  File "xxx/venv/lib/python3.10/site-packages/IPython/terminal/ipapp.py", line 318, in start
    self.shell.mainloop()
  File "xxx/venv/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 887, in mainloop
    self.interact()
  File "xxx/venv/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 872, in interact
    code = self.prompt_for_code()
  File "xxx/venv/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 811, in prompt_for_code
    text = self.pt_app.prompt(
  File "xxx/venv/lib/python3.10/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1035, in prompt
    return self.app.run(
  File "xxx/venv/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 955, in run
    loop = asyncio.get_event_loop()
jdkirkwood commented 1 year ago

Ubuntu 22.04 is packaged with Python 3.10.6, but, for example, other distributions could be at 3.10.11. The asyncio DeprecationWarning on get_event_loop() is removed in Python 3.10.9, but it will return in the future. https://github.com/python/cpython/commit/87f9b1d53f12538c579598304105974378677012

razvanioan commented 1 year ago

I can confirm that the depreciation warning is still there on 3.0.38 Same Python 3.10.6 installed on Ubuntu 22.04 LTS Package included in (jupyter) notebook raises this one

LordGrimmauld commented 7 months ago

Update: It seems not just Ubuntu is affected. I am running xonsh on Fedora 39 which now also ships Python 3.12. Manually applying the fix https://github.com/doronz88/python-prompt-toolkit/commit/a54890a59636fa234d584a14e0126a0cea8a43c3 mentioned in #1798 into the installed libs at least shuts up the deprecation warning and seems to work perfectly, at least from the little testing i did.

jonathanslenders commented 7 months ago

It think it should have been fixed by this PR: https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1782 I also released prompt_toolkit 3.0.40 Let me know if it still does not fix the issue.

LordGrimmauld commented 7 months ago

thank you for the official release, seems to have done exactly what i patched in by hand looking at the diffs on my install for the relevant file. Deprecation warning is and stays gone.

jdkirkwood commented 7 months ago

1806 works for me too. Many thanks @jonathanslenders