jupyter-xeus / xeus-python

Jupyter kernel for the Python programming language
BSD 3-Clause "New" or "Revised" License
436 stars 73 forks source link

object Future can't be used in 'await' expression #556

Open stefaneidelloth opened 2 years ago

stefaneidelloth commented 2 years ago

If I try to start a Notebook with xeus-python I get following error message:

Starting xeus-python kernel...

If you want to connect to this kernel from an other client, you can use the C:\python_env\App\WinPython\settings\runtime\kernel-472d9cc6-36b8-4d78-bb10-4ed43bef870b.json file.
Run with XEUS 2.4.1
2022-09-27 15:20:06,750 - ServerApp - ERROR - Uncaught exception GET /api/kernels/472d9cc6-36b8-4d78-bb10-4ed43bef870b/channels?session_id=e35572ba-ac5d-4c6d-8516-dddc8538acc6 (127.0.0.1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/api/kernels/472d9cc6-36b8-4d78-bb10-4ed43bef870b/channels?session_id=e35572ba-ac5d-4c6d-8516-dddc8538acc6', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\tornado\websocket.py", line 944, in _accept_connection
    await open_result
TypeError: object Future can't be used in 'await' expression
Exception in callback AddThreadSelectorEventLoop._handle_select([2296, 4424, 5152], [])
handle: <Handle AddThreadSelectorEventLoop._handle_select([2296, 4424, 5152], [])>
Traceback (most recent call last):
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\tornado\platform\asyncio.py", line 647, in _handle_select
    self._handle_event(r, self._readers)
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\tornado\platform\asyncio.py", line 661, in _handle_event
    callback()
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\tornado\platform\asyncio.py", line 206, in _handle_events
    handler_func(fileobj, events)
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\zmq\eventloop\zmqstream.py", line 578, in _handle_events
    self._handle_recv()
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\zmq\eventloop\zmqstream.py", line 607, in _handle_recv
    self._run_callback(callback, msg)
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\zmq\eventloop\zmqstream.py", line 557, in _run_callback
    callback(*args, **kwargs)
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\zmq\eventloop\zmqstream.py", line 279, in stream_callback
    return callback(self, msg)
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\jupyter_server\services\kernels\handlers.py", line 566, in _on_zmq_reply
    super()._on_zmq_reply(stream, msg)
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\jupyter_server\base\zmqhandlers.py", line 305, in _on_zmq_reply
    self.write_message(msg, binary=isinstance(msg, bytes))
  File "C:\python_env\App\WinPython\python-3.10.4.amd64\lib\site-packages\tornado\websocket.py", line 336, in write_message
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError

=> How to resolve this issue? jupyterlab 3.4.7 xeus-python 0.14.3 tornado 6.2 jupyterlab_server 2.15.2 jupyter-server 1.19.0

martinRenou commented 2 years ago

Thanks for opening an issue.

I have some questions, did you try to execute some code in the Notebook before getting this? Are you using starting the kernel from the command line and not from a JupyterLab/Notebook UI?

stefaneidelloth commented 2 years ago

a) Not explicitly (but I have a notebook open). b) No

Edit Starting with en empty Notebook seems to work and the issue sees that I have following code cell at the top of my exiting ipykernel notebook:

# The autoreload magic ensures that updates of the code, e.g.
# isi.utils.utils are applied without needing to restart the Python kernel.
%load_ext autoreload
%autoreload 2

After removing that cell I get another issue

ERROR: received bad message: No such comm target registered: jupyter.widget.control
Message type: comm_open
ERROR: received bad message: No such comm registered: d166cbf4-6f08-465f-8efb-192a4eac00d4
Message type: comm_msg

=> It seems that xeus-python is not ready to be used with my exiting ipykernel notebooks. => I found out that a newer version of ipykernel supports debugging and that it is not required to use xeus-python for debugging any more. Therefore 'll stick to ipykernel and this issue ticket can be closed if you want.

bldrvnlw commented 9 months ago

I also ran into possibly the same error using Jupyter Widgets (8.1.2). I have a xeus kernel with xeus-python connected to a jupyter_server. Trying to execute the following:

import ipywidgets as widgets

Results in the following error log:

ERROR: received bad message: No such comm registered: f207c173-fc88-4172-a384-9beda1763330
Message type: comm_msg

In the application hosting the xeus kernel I see the following call stack

    python311.dll!00007ffbbeebc472()    Unknown
>   libxeus-python.dll!pybind11::getattr(pybind11::handle obj, const char * name) Line 882  C++
    libxeus-python.dll!pybind11::detail::accessor_policies::str_attr::get(pybind11::handle obj, const char * key) Line 1055 C++
    libxeus-python.dll!pybind11::detail::accessor<pybind11::detail::accessor_policies::str_attr>::get_cache() Line 1034 C++
    libxeus-python.dll!pybind11::detail::accessor<pybind11::detail::accessor_policies::str_attr>::ptr() Line 1022   C++
    libxeus-python.dll!pybind11::detail::object_api<pybind11::detail::accessor<pybind11::detail::accessor_policies::str_attr>>::operator()<1>() Line 1672   C++
    libxeus-python.dll!xpyt::get_comm_module_impl::__l2::<lambda>() Line 152    C++
    libxeus-python.dll!pybind11::detail::argument_loader<>::call_impl<pybind11::object,pybind11::object <lambda>(void) &,pybind11::detail::void_type>(xpyt::get_comm_module_impl::__l2::pybind11::object <lambda>(void) & f, std::integer_sequence<unsigned __int64> __formal, pybind11::detail::void_type && __formal) Line 1480   C++
    libxeus-python.dll!pybind11::detail::argument_loader<>::call<pybind11::object,pybind11::detail::void_type,pybind11::object <lambda>(void) &>(xpyt::get_comm_module_impl::__l2::pybind11::object <lambda>(void) & f) Line 1448   C++
    libxeus-python.dll!pybind11::cpp_function::initialize::__l2::<lambda>(pybind11::detail::function_call & call) Line 253  C++
    libxeus-python.dll!pybind11::handle <lambda>(pybind11::detail::function_call &)::<lambda_invoker_cdecl>(pybind11::detail::function_call & call) Line 263    C++
    libxeus-python.dll!pybind11::cpp_function::dispatcher(_object * self, _object * args_in, _object * kwargs_in) Line 946  C++
    [External Code] 
    libxeus-python.dll!pybind11::detail::unpacking_collector<1>::call(_object * ptr) Line 1536  C++
    libxeus-python.dll!pybind11::detail::object_api<pybind11::detail::accessor<pybind11::detail::accessor_policies::str_attr>>::operator()<1,std::string const &,pybind11::arg_v,pybind11::arg_v>(const std::string & <args_0>, pybind11::arg_v && <args_1>, pybind11::arg_v && <args_2>) Line 1672 C++
    libxeus-python.dll!xpyt::interpreter::execute_request_impl(int __formal, const std::string & code, bool silent, bool store_history, nlohmann::json_abi_v3_11_3::basic_json<std::map,std::vector,std::string,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::json_abi_v3_11_3::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char>>,void> user_expressions, bool allow_stdin) Line 131  C++
    JupyterPlugin.dll!XeusInterpreter::execute_request_impl(int execution_counter, const std::string & code, bool store_history, bool silent, nlohmann::json_abi_v3_11_3::basic_json<std::map,std::vector,std::string,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::json_abi_v3_11_3::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char>>,void> user_expressions, bool allow_stdin) Line 31 C++
    libxeus.dll!xeus::xinterpreter::execute_request(const std::string & code, bool silent, bool store_history, nlohmann::json_abi_v3_11_3::basic_json<std::map,std::vector,std::string,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::json_abi_v3_11_3::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char>>,void> user_expressions, bool allow_stdin) Line 44    C++
    libxeus.dll!xeus::xkernel_core::execute_request(xeus::xmessage request, xeus::channel c) Line 238   C++
    libxeus.dll!xeus::xkernel_core::dispatch(xeus::xmessage msg, xeus::channel c) Line 203  C++
    libxeus.dll!xeus::xkernel_core::dispatch_shell(xeus::xmessage msg) Line 104 C++
    [External Code] 
    libxeus.dll!xeus::xserver::notify_shell_listener(xeus::xmessage msg) Line 88    C++
    libxeus-zmq.dll!xeus::xserver_zmq::poll(long timeout) Line 151  C++
    JupyterPlugin.dll!XeusServer::{ctor}::__l2::<lambda>() Line 12  C++
    JupyterPlugin.dll!QtPrivate::FunctorCall<QtPrivate::IndexesList<>,QtPrivate::List<>,void,void <lambda>(void)>::call(XeusServer::{ctor}::__l2::void <lambda>(void) & f, void * * arg) Line 163   C++
    JupyterPlugin.dll!QtPrivate::Functor<void <lambda>(void),0>::call<QtPrivate::List<>,void>(XeusServer::{ctor}::__l2::void <lambda>(void) & f, void * __formal, void * * arg) Line 278    C++
    JupyterPlugin.dll!QtPrivate::QFunctorSlotObject<void <lambda>(void),0,QtPrivate::List<>,void>::impl(int which, QtPrivate::QSlotObjectBase * this_, QObject * r, void * * a, bool * ret) Line 450    C++
    [External Code] 
    ManiVault Studio.exe!main(int argc, char * * argv) Line 219 C++
    [External Code] 

The obj.ptr is 0xcccccccccccccccc which give rise to an access violation extension