jupyter / jupyter_console

Jupyter Terminal Console

Home Page:http://jupyter-console.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

asyncio.wait() no longer accepts the loop keyword in Python 3.10

hroncok opened this issue · comments

Hello. The code in here:

main_task = asyncio.wait(tasks, loop=loop, return_when=asyncio.FIRST_COMPLETED)

Fails with this on Python 3.10:

$ jupyter-console 
Jupyter console 6.4.0

Python 3.10.0b3 (default, Jun 17 2021, 00:00:00) [GCC 11.1.1 20210617 (Red Hat 11.1.1-5)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.24.1 -- An enhanced Interactive Python. Type '?' for help.
Traceback (most recent call last):
  File "/usr/bin/jupyter-console", line 33, in <module>
    sys.exit(load_entry_point('jupyter-console==6.4.0', 'console_scripts', 'jupyter-console')())
  File "/usr/lib/python3.10/site-packages/jupyter_core/application.py", line 254, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/lib/python3.10/site-packages/traitlets/config/application.py", line 845, in launch_instance
    app.start()
  File "/usr/lib/python3.10/site-packages/jupyter_console/app.py", line 148, in start
    self.shell.mainloop()
  File "/usr/lib/python3.10/site-packages/jupyter_console/ptshell.py", line 664, in mainloop
    main_task = asyncio.wait(tasks, loop=loop, return_when=asyncio.FIRST_COMPLETED)
TypeError: wait() got an unexpected keyword argument 'loop'
sys:1: RuntimeWarning: coroutine 'ZMQTerminalInteractiveShell.interact' was never awaited
<mock-chroot> sh-5.1$ [IPKernelApp] WARNING | Parent appears to have exited, shutting down.
^C

The issue is that asyncio.wait() no longer accepts the loop keyword in python 3.10; see https://docs.python.org/3.10/library/asyncio-task.html#waiting-primitives.

Simply removing loop=loop fixes the problem, but I am not sure what Python versions does that support.

The docs say this is deprecated since 3.7. Jupyter continues to support Python 3.6 though. If Jupyter is part of the scientific community, then NEP 29 says that 3.6 should be dropped. Otherwise you may need a switch for Python 3.6.

This isn't fixed by #244, right? If not, then maybe you should submit a pull request that removes loop=loop and bumps the version to 3.7? After all Python 3.6 is end of life in 4 weeks. (December 2021)

That works! Thanks.

After fixing this error (removing 'loop=loop') mentioned above, I'm receiving this warning when I start jupyter-console:

c:\developing\python\lib\site-packages\zmq\_future.py:591: RuntimeWarning: Proactor event loop does not implement add_reader family of methods required for zmq. Registering an additional selector thread for add_reader support via tornado. Use `asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())` to avoid this warning.
  self._get_loop()

Thanks

Inside de console, I'm unable to execute any command (like '2+2'). I receive this exception:

c:\developing\python\lib\site-packages\jupyter_console\ptshell.py:852: RuntimeWarning: coroutine 'ZMQSocketChannel.msg_ready' was never awaited
  while self.client.iopub_channel.msg_ready():
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Unhandled exception in event loop:
  File "c:\developing\python\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "c:\developing\python\lib\site-packages\prompt_toolkit\input\win32.py", line 613, in ready
    callback()
  File "c:\developing\python\lib\site-packages\prompt_toolkit\application\application.py", line 690, in read_from_input
    self.key_processor.process_keys()
  File "c:\developing\python\lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 271, in process_keys
    self._process_coroutine.send(key_press)
  File "c:\developing\python\lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 186, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "c:\developing\python\lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 321, in _call_handler
    handler.call(event)
  File "c:\developing\python\lib\site-packages\prompt_toolkit\key_binding\key_bindings.py", line 124, in call
    result = self.handler(event)
  File "c:\developing\python\lib\site-packages\jupyter_console\ptshell.py", line 475, in _
    self.handle_iopub()
  File "c:\developing\python\lib\site-packages\jupyter_console\ptshell.py", line 854, in handle_iopub
    msg_type = sub_msg['header']['msg_type']

Exception 'coroutine' object is not subscriptable
Press ENTER to continue...
  • This bug was reported in: #246

Thanks

Fixed in #264.