From b33908f5dc41ddbdee5c9d0c19dcdff786a5f3c4 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 8 Mar 2024 09:55:41 +0100 Subject: [PATCH 001/112] Fix context errors --- include/xeus-python/xdebugger.hpp | 2 +- src/main.cpp | 7 +++---- src/xdebugger.cpp | 5 +++-- src/xdebugpy_client.cpp | 3 ++- src/xdebugpy_client.hpp | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/xeus-python/xdebugger.hpp b/include/xeus-python/xdebugger.hpp index 1b06fbab..ba0ff3e9 100644 --- a/include/xeus-python/xdebugger.hpp +++ b/include/xeus-python/xdebugger.hpp @@ -40,7 +40,7 @@ namespace xpyt using base_type = xeus::xdebugger_base; - debugger(zmq::context_t& context, + debugger(xeus::xcontext& context, const xeus::xconfiguration& config, const std::string& user_name, const std::string& session_id, diff --git a/src/main.cpp b/src/main.cpp index de81bf39..3e482314 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,8 @@ #include "xeus/xkernel_configuration.hpp" #include "xeus/xinterpreter.hpp" -#include "xeus-zmq/xserver_shell_main.hpp" +#include "xeus-zmq/xserver_zmq.hpp" +#include "xeus-zmq/xzmq_context.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -99,9 +100,7 @@ int main(int argc, char* argv[]) } delete[] argw; - using context_type = xeus::xcontext_impl; - using context_ptr = std::unique_ptr; - context_ptr context = context_ptr(new context_type()); + auto context = xeus::make_zmq_context(); // Instantiating the xeus xinterpreter bool raw_mode = xpyt::extract_option("-r", "--raw", argc, argv); diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index 967f004f..f264a595 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -26,6 +26,7 @@ #include "pybind11/stl.h" #include "xeus/xinterpreter.hpp" +#include "xeus/xeus_context.hpp" #include "xeus/xsystem.hpp" #include "xeus-zmq/xmiddleware.hpp" @@ -42,7 +43,7 @@ using namespace std::placeholders; namespace xpyt { - debugger::debugger(zmq::context_t& context, + debugger::debugger(xeus::xcontext& context, const xeus::xconfiguration& config, const std::string& user_name, const std::string& session_id, @@ -373,7 +374,7 @@ namespace xpyt const std::string& session_id, const nl::json& debugger_config) { - return std::unique_ptr(new debugger(context.get_wrapped_context(), + return std::unique_ptr(new debugger(context.get_wrapped_context(), config, user_name, session_id, debugger_config)); } } diff --git a/src/xdebugpy_client.cpp b/src/xdebugpy_client.cpp index 3addabbf..44b43a36 100644 --- a/src/xdebugpy_client.cpp +++ b/src/xdebugpy_client.cpp @@ -11,6 +11,7 @@ #include "zmq_addon.hpp" #include "nlohmann/json.hpp" #include "xeus/xmessage.hpp" +#include "xeus/xeus_context.hpp" #include "xdebugpy_client.hpp" #include @@ -20,7 +21,7 @@ namespace nl = nlohmann; namespace xpyt { - xdebugpy_client::xdebugpy_client(zmq::context_t& context, + xdebugpy_client::xdebugpy_client(xeus::xcontext& context, const xeus::xconfiguration& config, int socket_linger, const xdap_tcp_configuration& dap_config, diff --git a/src/xdebugpy_client.hpp b/src/xdebugpy_client.hpp index e9c59fbb..aec9e4e5 100644 --- a/src/xdebugpy_client.hpp +++ b/src/xdebugpy_client.hpp @@ -12,6 +12,7 @@ #define XPYT_DEBUGPY_CLIENT_HPP #include "xeus-zmq/xdap_tcp_client.hpp" +#include "xeus/xeus_context.hpp" namespace xpyt { @@ -25,7 +26,7 @@ namespace xpyt using base_type = xdap_tcp_client; using event_callback = base_type::event_callback; - xdebugpy_client(zmq::context_t& context, + xdebugpy_client(xeus::xcontext& context, const xeus::xconfiguration& config, int socket_linger, const xdap_tcp_configuration& dap_config, From 0adb618b016fb2feafb6482ff8dd3b51549c8977 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 8 Mar 2024 11:50:29 +0100 Subject: [PATCH 002/112] Working build --- src/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3e482314..ec797122 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,11 @@ #include #endif +#ifndef UVW_AS_LIB +#define UVW_AS_LIB +#include +#endif + #include "xeus/xeus_context.hpp" #include "xeus/xkernel.hpp" #include "xeus/xkernel_configuration.hpp" @@ -84,8 +89,35 @@ int main(int argc, char* argv[]) xpyt::set_pythonhome(); xpyt::print_pythonhome(); - // Instanciating the Python interpreter - py::scoped_interpreter guard; + // Instantiating the Python interpreter + py::scoped_interpreter guard{}; + + uv_loop_t* uv_loop_ptr{ nullptr }; + + { + py::gil_scoped_acquire acquire; + + // Instantiating the loop manually + py::exec(R"( + import asyncio + import uvloop + from uvloop.loop import libuv_get_loop_t_ptr + + print('Creating uvloop event loop') + loop = uvloop.new_event_loop() + asyncio.set_event_loop(loop) + print('uvloop event loop created') + )"); + + py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr()"); + void* raw_ptr = PyCapsule_GetPointer(py_loop_ptr.ptr(), nullptr); + if (!raw_ptr) + throw std::runtime_error("Failed to get libuv loop pointer"); + + uv_loop_ptr = static_cast(raw_ptr); + } + + auto loop_ptr = uvw::loop::create(uv_loop_ptr); // Setting argv wchar_t** argw = new wchar_t*[size_t(argc)]; @@ -130,6 +162,12 @@ int main(int argc, char* argv[]) nl::json debugger_config; debugger_config["python"] = executable; + auto make_xserver = [loop_ptr](xeus::xcontext& context, + const xeus::xconfiguration& config, + nl::json::error_handler_t eh) { + return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr); + }; + if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); @@ -138,7 +176,7 @@ int main(int argc, char* argv[]) xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_shell_main, + make_xserver, std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), @@ -158,7 +196,7 @@ int main(int argc, char* argv[]) xeus::xkernel kernel(xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_shell_main, + make_xserver, std::move(hist), nullptr, xpyt::make_python_debugger, From 7ec1dcec6d5fe7df2c93c8fd2dea924cf1ea6d18 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 8 Mar 2024 12:56:43 +0100 Subject: [PATCH 003/112] Working without debugger The debugger causes zmq errors somewhere --- src/main.cpp | 31 +++++++++++++++++++++++-------- src/xinterpreter.cpp | 1 + 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ec797122..10857372 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,8 +94,8 @@ int main(int argc, char* argv[]) uv_loop_t* uv_loop_ptr{ nullptr }; - { - py::gil_scoped_acquire acquire; + // { + // py::gil_scoped_acquire acquire; // Instantiating the loop manually py::exec(R"( @@ -109,16 +109,27 @@ int main(int argc, char* argv[]) print('uvloop event loop created') )"); - py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr()"); + py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr(loop)"); void* raw_ptr = PyCapsule_GetPointer(py_loop_ptr.ptr(), nullptr); if (!raw_ptr) + { + std::cout << "Got null pointer!\n"; throw std::runtime_error("Failed to get libuv loop pointer"); + } uv_loop_ptr = static_cast(raw_ptr); - } + std::cout << "Got a pointer!" << uv_loop_ptr << '\n'; + // } + if (!uv_loop_ptr) + { + throw std::runtime_error("Failed to get libuv loop pointer"); + std::cout << "This pointer is no good\n"; + } auto loop_ptr = uvw::loop::create(uv_loop_ptr); + std::cout << "Got a loop!\n"; + // Setting argv wchar_t** argw = new wchar_t*[size_t(argc)]; for(auto i = 0; i < argc; ++i) @@ -155,19 +166,23 @@ int main(int argc, char* argv[]) #ifdef XEUS_PYTHON_PYPI_WARNING std::clog << "WARNING: this instance of xeus-python has been installed from a PyPI wheel.\n" - "We recommend using a general-purpose package manager instead, such as Conda/Mamba.\n" + "We recommend using a ge7yuneral-purpose package manager instead, such as Conda/Mamba.\n" << std::endl; #endif nl::json debugger_config; debugger_config["python"] = executable; + std::cout << "Making a server\n"; + auto make_xserver = [loop_ptr](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr); }; + std::cout << "Done with the lambda\n"; + if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); @@ -179,9 +194,9 @@ int main(int argc, char* argv[]) make_xserver, std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, - xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), - xpyt::make_python_debugger, - debugger_config); + xeus::make_file_logger(xeus::xlogger::content, "xeus.log"))); + // xpyt::make_python_debugger, + // debugger_config); std::clog << "Starting xeus-python kernel...\n\n" diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 0078d5eb..761a3123 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -182,6 +182,7 @@ namespace xpyt kernel_res["traceback"] = error.m_traceback; } + kernel_res["status"] = "error"; return kernel_res; } From 71cf45cd4912aee392f83fddc2daeaf5b6f7fafd Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 11 Mar 2024 16:03:13 +0100 Subject: [PATCH 004/112] Not working --- include/xeus-python/xinterpreter.hpp | 2 +- src/main.cpp | 74 +++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/include/xeus-python/xinterpreter.hpp b/include/xeus-python/xinterpreter.hpp index 1382a024..d9f272ca 100644 --- a/include/xeus-python/xinterpreter.hpp +++ b/include/xeus-python/xinterpreter.hpp @@ -91,7 +91,7 @@ namespace xpyt // is started, m_release_gil_at_startup has to be set to false to prevent // releasing it again in configure_impl(). // - bool m_release_gil_at_startup = true; + bool m_release_gil_at_startup = false; gil_scoped_release_ptr m_release_gil = nullptr; bool m_redirect_output_enabled; diff --git a/src/main.cpp b/src/main.cpp index 10857372..ce3390e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ #include "xeus-zmq/xserver_zmq.hpp" #include "xeus-zmq/xzmq_context.hpp" +#include "xeus-zmq/hook_base.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -46,6 +47,51 @@ namespace py = pybind11; +class py_hook : public xeus::hook_base +{ +public: + py_hook() = default; + + void pre_hook() override + { + std::cout << "pre_handle\n"; + p_acquire = new py::gil_scoped_acquire(); + p_release = new py::gil_scoped_release(); + } + + void post_hook() override + { + std::cout << "post_handle\n"; + if (p_acquire) + { + delete p_release; + p_release = nullptr; + delete p_acquire; + p_acquire = nullptr; + std::cout << "done deleting post\n"; + } + std::cout << "post_handle done\n"; + + } + + void run(std::shared_ptr) override + { + std::cout << "Running\n"; + py::gil_scoped_acquire acquire; + py::exec(R"( + import asyncio + loop = asyncio.get_event_loop() + loop.run_forever() + )"); + } + +private: + py::gil_scoped_acquire* p_acquire = nullptr; + py::gil_scoped_release* p_release = nullptr; +}; + + + int main(int argc, char* argv[]) { @@ -94,8 +140,8 @@ int main(int argc, char* argv[]) uv_loop_t* uv_loop_ptr{ nullptr }; - // { - // py::gil_scoped_acquire acquire; + { + py::gil_scoped_acquire acquire; // Instantiating the loop manually py::exec(R"( @@ -119,7 +165,7 @@ int main(int argc, char* argv[]) uv_loop_ptr = static_cast(raw_ptr); std::cout << "Got a pointer!" << uv_loop_ptr << '\n'; - // } + } if (!uv_loop_ptr) { @@ -166,19 +212,21 @@ int main(int argc, char* argv[]) #ifdef XEUS_PYTHON_PYPI_WARNING std::clog << "WARNING: this instance of xeus-python has been installed from a PyPI wheel.\n" - "We recommend using a ge7yuneral-purpose package manager instead, such as Conda/Mamba.\n" + "We recommend using a general-purpose package manager instead, such as Conda/Mamba.\n" << std::endl; #endif nl::json debugger_config; debugger_config["python"] = executable; + auto hook = std::make_unique(); + std::cout << "Making a server\n"; - auto make_xserver = [loop_ptr](xeus::xcontext& context, + auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { - return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr); + return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(hook)); }; std::cout << "Done with the lambda\n"; @@ -204,7 +252,21 @@ int main(int argc, char* argv[]) " the " + connection_filename + " file." << std::endl; + std::cout << "Starting kernel\n"; + kernel.start(); + + std::cout << "Kernel started\n"; + + py::gil_scoped_acquire acquire; + py::exec(R"( + import asyncio + loop = asyncio.get_event_loop() + loop.run_forever() + )"); + + + std::cout << "Ran the loop\n"; } else { From 6526c653c2878652e4bfc745499ca217b1951034 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Tue, 12 Mar 2024 10:05:49 +0100 Subject: [PATCH 005/112] Partially working --- src/main.cpp | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ce3390e9..5b95994c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,45 +54,42 @@ class py_hook : public xeus::hook_base void pre_hook() override { - std::cout << "pre_handle\n"; - p_acquire = new py::gil_scoped_acquire(); - p_release = new py::gil_scoped_release(); + // p_release = new py::gil_scoped_release(); + // p_acquire = new py::gil_scoped_acquire(); + std::cout << "Prehook\n"; } void post_hook() override { - std::cout << "post_handle\n"; - if (p_acquire) - { - delete p_release; - p_release = nullptr; - delete p_acquire; - p_acquire = nullptr; - std::cout << "done deleting post\n"; - } - std::cout << "post_handle done\n"; + // delete p_acquire; + // delete p_release; + // p_acquire = nullptr; + // p_release = nullptr; + std::cout << "Posthook\n"; } void run(std::shared_ptr) override { - std::cout << "Running\n"; + std::cout << "Overriden run\n"; + py::gil_scoped_acquire acquire; + std::cout << "After acquire gil\n"; py::exec(R"( import asyncio loop = asyncio.get_event_loop() + print('got a loop', loop) loop.run_forever() )"); } private: - py::gil_scoped_acquire* p_acquire = nullptr; - py::gil_scoped_release* p_release = nullptr; + py::gil_scoped_acquire* p_acquire{ nullptr }; + py::gil_scoped_release* p_release{ nullptr }; }; - int main(int argc, char* argv[]) { if (xpyt::should_print_version(argc, argv)) @@ -258,15 +255,6 @@ int main(int argc, char* argv[]) std::cout << "Kernel started\n"; - py::gil_scoped_acquire acquire; - py::exec(R"( - import asyncio - loop = asyncio.get_event_loop() - loop.run_forever() - )"); - - - std::cout << "Ran the loop\n"; } else { From f167fdbb78af28b6159402585a932fdd5dcd5fdc Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Tue, 12 Mar 2024 11:26:29 +0100 Subject: [PATCH 006/112] Working --- src/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5b95994c..1c5020e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,16 +55,17 @@ class py_hook : public xeus::hook_base void pre_hook() override { // p_release = new py::gil_scoped_release(); - // p_acquire = new py::gil_scoped_acquire(); - std::cout << "Prehook\n"; + if (!p_acquire) + { + std::cout << "Acquiring GIL\n"; + p_acquire = new py::gil_scoped_acquire(); + } } void post_hook() override { - // delete p_acquire; - // delete p_release; - // p_acquire = nullptr; - // p_release = nullptr; + delete p_acquire; + p_acquire = nullptr; std::cout << "Posthook\n"; } @@ -85,7 +86,6 @@ class py_hook : public xeus::hook_base private: py::gil_scoped_acquire* p_acquire{ nullptr }; - py::gil_scoped_release* p_release{ nullptr }; }; From f1290dcc28b8b00a09c88b8b7a2ffe22fdbcec83 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Wed, 13 Mar 2024 19:15:10 +0100 Subject: [PATCH 007/112] Rename xhook --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c5020e3..5ce20a38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ #include "xeus-zmq/xserver_zmq.hpp" #include "xeus-zmq/xzmq_context.hpp" -#include "xeus-zmq/hook_base.hpp" +#include "xeus-zmq/xhook_base.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -47,7 +47,7 @@ namespace py = pybind11; -class py_hook : public xeus::hook_base +class py_hook : public xeus::xhook_base { public: py_hook() = default; From ca0b1fd6df071dc547785a15b68928dfeff50f2d Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Fri, 15 Mar 2024 17:26:40 +0100 Subject: [PATCH 008/112] Move hook --- CMakeLists.txt | 2 ++ include/xeus-python/xhook.hpp | 40 +++++++++++++++++++++++++++ src/main.cpp | 48 +++------------------------------ src/xhook.cpp | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 45 deletions(-) create mode 100644 include/xeus-python/xhook.hpp create mode 100644 src/xhook.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 89f0a771..2b941d98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,7 @@ set(XEUS_PYTHON_SRC src/xdebugpy_client.cpp src/xdisplay.cpp src/xdisplay.hpp + src/xhook.cpp src/xinput.cpp src/xinput.hpp src/xinspect.cpp @@ -175,6 +176,7 @@ set(XEUS_PYTHON_HEADERS include/xeus-python/xinterpreter_raw.hpp include/xeus-python/xtraceback.hpp include/xeus-python/xutils.hpp + include/xeus-python/xhook.hpp ) set(XPYTHON_SRC diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp new file mode 100644 index 00000000..dfb7471e --- /dev/null +++ b/include/xeus-python/xhook.hpp @@ -0,0 +1,40 @@ +/*************************************************************************** +* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * +* Wolf Vollprecht * +* Copyright (c) 2018, QuantStack +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef XPYT_HOOK_HPP +#define XPYT_HOOK_HPP + +#include "xeus-python/xeus_python_config.hpp" +#include "xeus-zmq/xhook_base.hpp" + +#include "pybind11/embed.h" +#include "pybind11/pybind11.h" + +namespace py = pybind11; + +namespace xpyt +{ + XEUS_PYTHON_API + class hook : public xeus::xhook_base + { + public: + hook() = default; + + void pre_hook() override; + void post_hook() override; + void run(std::shared_ptr loop) override; + + private: + py::gil_scoped_acquire* p_acquire{ nullptr}; + }; + +} + +#endif diff --git a/src/main.cpp b/src/main.cpp index 5ce20a38..6382caf0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,52 +44,10 @@ #include "xeus-python/xpaths.hpp" #include "xeus-python/xeus_python_config.hpp" #include "xeus-python/xutils.hpp" +#include "xeus-python/xhook.hpp" namespace py = pybind11; -class py_hook : public xeus::xhook_base -{ -public: - py_hook() = default; - - void pre_hook() override - { - // p_release = new py::gil_scoped_release(); - if (!p_acquire) - { - std::cout << "Acquiring GIL\n"; - p_acquire = new py::gil_scoped_acquire(); - } - } - - void post_hook() override - { - delete p_acquire; - p_acquire = nullptr; - std::cout << "Posthook\n"; - - } - - void run(std::shared_ptr) override - { - std::cout << "Overriden run\n"; - - py::gil_scoped_acquire acquire; - std::cout << "After acquire gil\n"; - py::exec(R"( - import asyncio - loop = asyncio.get_event_loop() - print('got a loop', loop) - loop.run_forever() - )"); - } - -private: - py::gil_scoped_acquire* p_acquire{ nullptr }; -}; - - - int main(int argc, char* argv[]) { if (xpyt::should_print_version(argc, argv)) @@ -216,14 +174,14 @@ int main(int argc, char* argv[]) nl::json debugger_config; debugger_config["python"] = executable; - auto hook = std::make_unique(); + auto py_hook = std::make_unique(); std::cout << "Making a server\n"; auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { - return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(hook)); + return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(py_hook)); }; std::cout << "Done with the lambda\n"; diff --git a/src/xhook.cpp b/src/xhook.cpp new file mode 100644 index 00000000..402a81d4 --- /dev/null +++ b/src/xhook.cpp @@ -0,0 +1,51 @@ +/*************************************************************************** +* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * +* Wolf Vollprecht * +* Copyright (c) 2018, QuantStack +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef UVW_AS_LIB +#define UVW_AS_LIB +#include +#endif + +#include // REMOVE + +#include "xeus-python/xhook.hpp" + +#include "pybind11/embed.h" +#include "pybind11/pybind11.h" + +namespace py = pybind11; + +namespace xpyt +{ + void hook::pre_hook() + { + if (!p_acquire) + { + std::cout << "Acquiring GIL" << std::endl; + p_acquire = new py::gil_scoped_acquire(); + } + } + + void hook::post_hook() + { + delete p_acquire; + p_acquire = nullptr; + std::cout << "Deleted GIL" << std::endl; + } + + void hook::run(std::shared_ptr /* loop */) + { + std::cout << "Running loop" << std::endl; + py::gil_scoped_acquire acquire; + py::module asyncio = py::module::import("asyncio"); + py::object loop = asyncio.attr("get_event_loop")(); + loop.attr("run_forever")(); + } +} From b94c5461ccf4a85a02ae45592fea1a4f9deee17c Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 18 Mar 2024 18:00:15 +0100 Subject: [PATCH 009/112] Add uvw dependency --- CMakeLists.txt | 8 +++++++- environment-dev.yml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b941d98..0f6a040b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,9 @@ else () endif () endif() +find_library(UVW_LIBRARY uvw) +find_path(UVW_INCLUDE_DIR uvw.hpp) + # Source files # ============ @@ -306,7 +309,10 @@ macro(xpyt_create_target target_name src headers linkage output_name) set(XPYT_XEUS_TARGET xeus-zmq-static) endif () - target_link_libraries(${target_name} PUBLIC ${XPYT_XEUS_TARGET} xtl PRIVATE pybind11::pybind11 pybind11_json) + target_link_libraries(${target_name} + PUBLIC ${XPYT_XEUS_TARGET} xtl ${UVW_LIBRARY} + PRIVATE pybind11::pybind11 pybind11_json + ) if (WIN32 OR CYGWIN) target_link_libraries(${target_name} PRIVATE ${PYTHON_LIBRARIES}) elseif (APPLE) diff --git a/environment-dev.yml b/environment-dev.yml index fb4fb18d..1117f6d9 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -15,6 +15,7 @@ dependencies: - pybind11_json>=0.2.6,<0.3 - xeus-python-shell>=0.5.0,<0.6 - debugpy>=1.6.5 + - libuvw # Test dependencies - pytest - nbval From e4241b3413690707f17fb19d35b970d92ae89795 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 18 Mar 2024 18:54:46 +0100 Subject: [PATCH 010/112] Ignore pybind11 visibility warning --- include/xeus-python/xhook.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp index dfb7471e..7dc2a126 100644 --- a/include/xeus-python/xhook.hpp +++ b/include/xeus-python/xhook.hpp @@ -11,6 +11,15 @@ #ifndef XPYT_HOOK_HPP #define XPYT_HOOK_HPP +// pybind11 code internally forces hidden visibility on all internal code, but +// if non-hidden (and thus exported) code attempts to include a pybind type +// this warning occurs: +// 'xpyt::hook' declared with greater visibility than the type of its +// field 'xpyt::hook::p_acquire' [-Wattributes] +#ifdef __GNUC__ + #pragma GCC diagnostic ignored "-Wattributes" +#endif + #include "xeus-python/xeus_python_config.hpp" #include "xeus-zmq/xhook_base.hpp" From edad43f2fd403df29e0ffdf4f55d66b23bf8fef5 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Mon, 18 Mar 2024 19:30:51 +0100 Subject: [PATCH 011/112] Clean hook --- src/xhook.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/xhook.cpp b/src/xhook.cpp index 402a81d4..5898b673 100644 --- a/src/xhook.cpp +++ b/src/xhook.cpp @@ -13,8 +13,6 @@ #include #endif -#include // REMOVE - #include "xeus-python/xhook.hpp" #include "pybind11/embed.h" @@ -28,7 +26,6 @@ namespace xpyt { if (!p_acquire) { - std::cout << "Acquiring GIL" << std::endl; p_acquire = new py::gil_scoped_acquire(); } } @@ -37,12 +34,10 @@ namespace xpyt { delete p_acquire; p_acquire = nullptr; - std::cout << "Deleted GIL" << std::endl; } void hook::run(std::shared_ptr /* loop */) { - std::cout << "Running loop" << std::endl; py::gil_scoped_acquire acquire; py::module asyncio = py::module::import("asyncio"); py::object loop = asyncio.attr("get_event_loop")(); From 8c685c68545db73bfbaad81f89bb0d9889664678 Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Tue, 19 Mar 2024 10:32:22 +0100 Subject: [PATCH 012/112] Clean main --- src/main.cpp | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6382caf0..ed7be810 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,39 +98,28 @@ int main(int argc, char* argv[]) { py::gil_scoped_acquire acquire; - // Instantiating the loop manually - py::exec(R"( - import asyncio - import uvloop - from uvloop.loop import libuv_get_loop_t_ptr - - print('Creating uvloop event loop') - loop = uvloop.new_event_loop() - asyncio.set_event_loop(loop) - print('uvloop event loop created') - )"); - - py::object py_loop_ptr = py::eval("libuv_get_loop_t_ptr(loop)"); + // Create a uvloop and get pointer to the loop + py::module asyncio = py::module::import("asyncio"); + py::module uvloop = py::module::import("uvloop"); + py::object loop = uvloop.attr("new_event_loop")(); + asyncio.attr("set_event_loop")(loop); + py::object py_loop_ptr = uvloop.attr("loop").attr("libuv_get_loop_t_ptr")(loop); + void* raw_ptr = PyCapsule_GetPointer(py_loop_ptr.ptr(), nullptr); if (!raw_ptr) { - std::cout << "Got null pointer!\n"; - throw std::runtime_error("Failed to get libuv loop pointer"); + throw std::runtime_error("Failed to get uvloop pointer"); } uv_loop_ptr = static_cast(raw_ptr); - std::cout << "Got a pointer!" << uv_loop_ptr << '\n'; } if (!uv_loop_ptr) { throw std::runtime_error("Failed to get libuv loop pointer"); - std::cout << "This pointer is no good\n"; } auto loop_ptr = uvw::loop::create(uv_loop_ptr); - std::cout << "Got a loop!\n"; - // Setting argv wchar_t** argw = new wchar_t*[size_t(argc)]; for(auto i = 0; i < argc; ++i) @@ -176,16 +165,12 @@ int main(int argc, char* argv[]) auto py_hook = std::make_unique(); - std::cout << "Making a server\n"; - auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(py_hook)); }; - std::cout << "Done with the lambda\n"; - if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); @@ -207,12 +192,7 @@ int main(int argc, char* argv[]) " the " + connection_filename + " file." << std::endl; - std::cout << "Starting kernel\n"; - kernel.start(); - - std::cout << "Kernel started\n"; - } else { From 3de58650d8eb12b48bfc7bd60a6746c009305d8e Mon Sep 17 00:00:00 2001 From: Isabel Paredes Date: Wed, 17 Apr 2024 10:37:40 +0200 Subject: [PATCH 013/112] Fix hook implementaion --- include/xeus-python/xhook.hpp | 11 +++++++---- src/xhook.cpp | 11 ++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp index 7dc2a126..e79725e3 100644 --- a/include/xeus-python/xhook.hpp +++ b/include/xeus-python/xhook.hpp @@ -34,13 +34,16 @@ namespace xpyt class hook : public xeus::xhook_base { public: - hook() = default; - void pre_hook() override; - void post_hook() override; - void run(std::shared_ptr loop) override; + hook() = default; + virtual ~hook(); private: + + void pre_hook_impl() override; + void post_hook_impl() override; + void run_impl(std::shared_ptr loop) override; + py::gil_scoped_acquire* p_acquire{ nullptr}; }; diff --git a/src/xhook.cpp b/src/xhook.cpp index 5898b673..5fcf2db1 100644 --- a/src/xhook.cpp +++ b/src/xhook.cpp @@ -22,7 +22,12 @@ namespace py = pybind11; namespace xpyt { - void hook::pre_hook() + hook::~hook() + { + delete p_acquire; + } + + void hook::pre_hook_impl() { if (!p_acquire) { @@ -30,13 +35,13 @@ namespace xpyt } } - void hook::post_hook() + void hook::post_hook_impl() { delete p_acquire; p_acquire = nullptr; } - void hook::run(std::shared_ptr /* loop */) + void hook::run_impl(std::shared_ptr /* loop */) { py::gil_scoped_acquire acquire; py::module asyncio = py::module::import("asyncio"); From 44f8a31992f821a74cbae9fdfebd4e0799d5ff6b Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 17 Dec 2025 09:15:46 +0100 Subject: [PATCH 014/112] updates --- CMakeLists.txt | 6 ++++-- include/xeus-python/xhook.hpp | 2 +- src/main.cpp | 13 +++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08ebbd73..65c91971 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,8 @@ else () if (NOT TARGET xeus-zmq AND NOT TARGET xeus-zmq-static) find_package(xeus-zmq ${xeus-zmq_REQUIRED_VERSION} REQUIRED) endif () + + find_package(xeus-uv REQUIRED) endif() find_library(UVW_LIBRARY uvw) @@ -323,7 +325,7 @@ macro(xpyt_create_target target_name src headers linkage output_name) endif () target_link_libraries(${target_name} - PUBLIC ${XPYT_XEUS_TARGET} xtl ${UVW_LIBRARY} + PUBLIC ${XPYT_XEUS_TARGET} ${UVW_LIBRARY} PRIVATE pybind11::pybind11 pybind11_json ) if (WIN32 OR CYGWIN) @@ -379,7 +381,7 @@ endif () if (XPYT_BUILD_XPYTHON_EXECUTABLE) add_executable(xpython ${XPYTHON_SRC}) - target_link_libraries(xpython PRIVATE pybind11::embed) + target_link_libraries(xpython PRIVATE xeus-uv pybind11::embed ) xpyt_set_common_options(xpython) xpyt_set_kernel_options(xpython) diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp index e79725e3..033edc16 100644 --- a/include/xeus-python/xhook.hpp +++ b/include/xeus-python/xhook.hpp @@ -21,7 +21,7 @@ #endif #include "xeus-python/xeus_python_config.hpp" -#include "xeus-zmq/xhook_base.hpp" +#include "xeus-uv/xhook_base.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" diff --git a/src/main.cpp b/src/main.cpp index e8e52d2b..fcd4ffce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,11 @@ #include "xeus-zmq/xserver_zmq.hpp" #include "xeus-zmq/xzmq_context.hpp" -#include "xeus-zmq/xhook_base.hpp" + + +#include "xeus-uv/xserver_uv.hpp" +#include "xeus-uv/xhook_base.hpp" + #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -143,8 +147,7 @@ int main(int argc, char* argv[]) } delete[] argw; - // Instantiating the Python interpreter - py::scoped_interpreter guard; + std::unique_ptr context = xeus::make_zmq_context(); @@ -178,10 +181,12 @@ int main(int argc, char* argv[]) auto py_hook = std::make_unique(); + + auto make_xserver = [&](xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) { - return xeus::make_xserver_uv_shell_main(context, config, eh, loop_ptr, std::move(py_hook)); + return xeus::make_xserver_uv(context, config, eh, loop_ptr, std::move(py_hook)); }; if (!connection_filename.empty()) From 8a7cc27d704ff795e508cdae0d07843c38ca3a56 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 17 Dec 2025 09:17:54 +0100 Subject: [PATCH 015/112] remove mac-13 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9870f650..c79417e8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubuntu-24.04, macos-13, macos-14] + os: [ubuntu-22.04, ubuntu-24.04, macos-14] build_type: [static_build, shared_build] steps: From 0a8469fcade91373d0264a8bf6d4c51f0a71cd0f Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 17 Dec 2025 09:56:46 +0100 Subject: [PATCH 016/112] movin find uv related code to non-emscripten branch --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65c91971..72053244 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,10 +107,11 @@ else () endif () find_package(xeus-uv REQUIRED) + find_library(UVW_LIBRARY uvw) + find_path(UVW_INCLUDE_DIR uvw.hpp) endif() -find_library(UVW_LIBRARY uvw) -find_path(UVW_INCLUDE_DIR uvw.hpp) + # Configuration # ============= From 3f93c9b58c2e0996aed98a1c91502c383c340e32 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 11:15:08 +0100 Subject: [PATCH 017/112] working --- include/xeus-python/xinterpreter.hpp | 14 +++ notebooks/xeus-python.ipynb | 54 ++++++++++-- src/main.cpp | 5 ++ src/xinterpreter.cpp | 125 ++++++++++++++++++--------- 4 files changed, 148 insertions(+), 50 deletions(-) diff --git a/include/xeus-python/xinterpreter.hpp b/include/xeus-python/xinterpreter.hpp index 6c38affd..6ffdae81 100644 --- a/include/xeus-python/xinterpreter.hpp +++ b/include/xeus-python/xinterpreter.hpp @@ -101,6 +101,20 @@ namespace xpyt private: + // helper methods: + void execute_request_impl_sync(send_reply_callback cb, + int execution_counter, + const std::string& code, + xeus::execute_request_config config, + nl::json user_expressions); + + void execute_request_impl_async(send_reply_callback cb, + int execution_counter, + const std::string& code, + xeus::execute_request_config config, + nl::json user_expressions); + + virtual void instanciate_ipython_shell(); virtual bool use_jedi_for_completion() const; }; diff --git a/notebooks/xeus-python.ipynb b/notebooks/xeus-python.ipynb index 12a0b75b..026d828c 100644 --- a/notebooks/xeus-python.ipynb +++ b/notebooks/xeus-python.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -28,18 +28,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7921" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "b = 89\n", "\n", @@ -51,9 +73,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "print" ] @@ -653,15 +686,18 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.9 (XPython)", + "display_name": "Python 3.13 (XPython)", "language": "python", "name": "xpython" }, "language_info": { + "codemirror_mode": "{\"name\": \"ipython\", \"version\": 3}", "file_extension": ".py", "mimetype": "text/x-python", "name": "python", - "version": "3.9.1" + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.11" } }, "nbformat": 4, diff --git a/src/main.cpp b/src/main.cpp index fcd4ffce..f1bf3733 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,9 +111,12 @@ int main(int argc, char* argv[]) py::module uvloop = py::module::import("uvloop"); py::object loop = uvloop.attr("new_event_loop")(); asyncio.attr("set_event_loop")(loop); + + std::cout<<"getting uv loop pointer from uvloop"< traceback; + + + + + auto when_done_callback_lambda = [this, cb, config, user_expressions]() { + py::gil_scoped_acquire acquire; + // Placeholder for any actions to perform when execution is done + + + + // Get payload + nl::json payload = this->m_ipython_shell.attr("payload_manager").attr("read_payload")(); + this->m_ipython_shell.attr("payload_manager").attr("clear_payload")(); + + // if(exception_occurred) + // { + // cb(xeus::create_error_reply(ename, evalue, traceback)); + // return; + // } + + if (this->m_ipython_shell.attr("last_error").is_none()) + { + nl::json user_exprs = this->m_ipython_shell.attr("user_expressions")(user_expressions); + cb(xeus::create_successful_reply(payload, user_exprs)); + } + else + { + py::list pyerror = this->m_ipython_shell.attr("last_error"); + + xerror error = extract_error(pyerror); + + if (!config.silent) + { + publish_execution_error(error.m_ename, error.m_evalue, error.m_traceback); + } + + cb(xeus::create_error_reply(error.m_ename, error.m_evalue, error.m_traceback)); + } + }; + std::function when_done_callback = when_done_callback_lambda; + + + try { - m_ipython_shell.attr("run_cell")(code, "store_history"_a=config.store_history, "silent"_a=config.silent); + m_ipython_shell.attr("run_cell_async")(code, when_done_callback, "store_history"_a=config.store_history, "silent"_a=config.silent); } catch(std::runtime_error& e) { @@ -171,34 +219,12 @@ namespace xpyt exception_occurred = true; } - // Get payload - nl::json payload = m_ipython_shell.attr("payload_manager").attr("read_payload")(); - m_ipython_shell.attr("payload_manager").attr("clear_payload")(); - if(exception_occurred) - { - cb(xeus::create_error_reply(ename, evalue, traceback)); - return; - } - if (m_ipython_shell.attr("last_error").is_none()) - { - nl::json user_exprs = m_ipython_shell.attr("user_expressions")(user_expressions); - cb(xeus::create_successful_reply(payload, user_exprs)); - } - else - { - py::list pyerror = m_ipython_shell.attr("last_error"); - xerror error = extract_error(pyerror); - if (!config.silent) - { - publish_execution_error(error.m_ename, error.m_evalue, error.m_traceback); - } - cb(xeus::create_error_reply(error.m_ename, error.m_evalue, error.m_traceback)); - } + } nl::json interpreter::complete_request_impl( @@ -266,8 +292,7 @@ namespace xpyt } nl::json interpreter::kernel_info_request_impl() - { - + { /* The jupyter-console banner for xeus-python is the following: __ _____ _ _ ___ \ \/ / _ \ | | / __| @@ -300,21 +325,39 @@ namespace xpyt {"url", "https://xeus-python.readthedocs.io"} }); - return xeus::create_info_reply( - "5.3", // protocol_version - "xeus-python", // implementation - XPYT_VERSION, // implementation_version - "python", // language_name - PY_VERSION, // language_version - "text/x-python", // language_mimetype - ".py", // language_file_extension - "ipython" + std::to_string(PY_MAJOR_VERSION), // pygments_lexer - R"({"name": "ipython", "version": )" + std::to_string(PY_MAJOR_VERSION) + "}", // language_codemirror_mode - "python", // language_nbconvert_exporter - banner, // banner - (PY_MAJOR_VERSION != 3) || (PY_MINOR_VERSION != 13), // debugger - help_links // help_links - ); + // return xeus::create_info_reply( + // "5.3", // protocol_version + // "xeus-python", // implementation + // XPYT_VERSION, // implementation_version + // "python", // language_name + // PY_VERSION, // language_version + // "text/x-python", // language_mimetype + // ".py", // language_file_extension + // "ipython" + std::to_string(PY_MAJOR_VERSION), // pygments_lexer + // R"({"name": "ipython", "version": )" + std::to_string(PY_MAJOR_VERSION) + "}", // language_codemirror_mode + // "python", // language_nbconvert_exporter + // banner, // banner + // (PY_MAJOR_VERSION != 3) || (PY_MINOR_VERSION != 13), // debugger + // help_links // help_links + // ); + + nl::json kernel_res; + kernel_res["status"] = "ok"; + kernel_res["protocol_version"] = "5.3"; + kernel_res["implementation"] = "xeus-python"; + kernel_res["implementation_version"] = XPYT_VERSION; + kernel_res["language_info"]["name"] = "python"; + kernel_res["language_info"]["version"] = PY_VERSION; + kernel_res["language_info"]["mimetype"] = "text/x-python"; + kernel_res["language_info"]["file_extension"] = ".py"; + kernel_res["language_info"]["pygments_lexer"] = "ipython" + std::to_string(PY_MAJOR_VERSION); + //kernel_res["language_info"]["codemirror_mode"] = R"({"name": "ipython", "version": )" + std::to_string(PY_MAJOR_VERSION) + "}"; + kernel_res["language_info"]["nbconvert_exporter"] = "python"; + kernel_res["banner"] = banner; + kernel_res["debugger"] = false; + kernel_res["help_links"] = help_links; + return kernel_res; + } void interpreter::shutdown_request_impl() From 9a3468be7e19d2c479e5758a873cde6d8e851577 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:27:35 +0100 Subject: [PATCH 018/112] libuv --- .github/workflows/deploy-github-page.yml | 13 ++++++++++++- environment-wasm-host.yml | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 4f60b9f0..18810490 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -47,6 +47,12 @@ jobs: set -eux + + URL=https://github.com/DerThorsten/xeus-python-shell/archive/refs/heads/libuv.zip + curl -L $URL -o xeus-python-shell.zip + unzip xeus-python-shell.zip + + export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-python-wasm-host echo "PREFIX=$PREFIX" >> $GITHUB_ENV @@ -60,13 +66,18 @@ jobs: emmake make -j${{ env.ncpus }} install + + + - name: Jupyter Lite integration shell: bash -l {0} run: | jupyter lite build \ --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ - --output-dir dist + --output-dir dist \ + --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + - name: Upload artifact uses: actions/upload-pages-artifact@v4 diff --git a/environment-wasm-host.yml b/environment-wasm-host.yml index 72e89111..0c3a1034 100644 --- a/environment-wasm-host.yml +++ b/environment-wasm-host.yml @@ -12,9 +12,9 @@ dependencies: - numpy - xeus-lite - xeus - - xeus-python-shell>=0.6.3 - pyjs >=2,<3 - libpython - zstd - openssl - xz + # - xeus-python-shell>=0.6.3 From 9dd02a4661c0f457a9d5e941a3ad083896a91d6d Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:30:11 +0100 Subject: [PATCH 019/112] libuv --- .github/workflows/deploy-github-page.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 18810490..f68b7d83 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -49,8 +49,8 @@ jobs: URL=https://github.com/DerThorsten/xeus-python-shell/archive/refs/heads/libuv.zip - curl -L $URL -o xeus-python-shell.zip - unzip xeus-python-shell.zip + curl -L $URL -o xeus-python-shell-libuv.zip + unzip xeus-python-shell-libuv.zip export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-python-wasm-host @@ -76,7 +76,7 @@ jobs: --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ --output-dir dist \ - --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" - name: Upload artifact From 565eb44bb520ae2ae139a60ecbb5b01098306f71 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:35:40 +0100 Subject: [PATCH 020/112] path --- .github/workflows/deploy-github-page.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index f68b7d83..36e30f5e 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -76,7 +76,7 @@ jobs: --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ --output-dir dist \ - --XeusAddon.mounts=/home/runner/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + --XeusAddon.mounts=/home/runner/work/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" - name: Upload artifact From 8924b65e6a798bce5eb632a04f6c595c54409b32 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:44:38 +0100 Subject: [PATCH 021/112] path --- .github/workflows/deploy-github-page.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 36e30f5e..6929951a 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -33,7 +33,7 @@ jobs: environment-file: environment-wasm-build.yml init-shell: bash environment-name: xeus-python-wasm-build - + - name: Set ncpus run: echo "ncpus=$(nproc --all)" >> $GITHUB_ENV @@ -72,11 +72,12 @@ jobs: - name: Jupyter Lite integration shell: bash -l {0} run: | + THIS_DIR=$(pwd) jupyter lite build \ --XeusAddon.prefix=${{ env.PREFIX }} \ --contents notebooks/ \ --output-dir dist \ - --XeusAddon.mounts=/home/runner/work/xeus-python/xeus-python-shell-libuv/xeus_python_shell/:"/lib/python3.13/site-packages/xeus_python_shell/" + --XeusAddon.mounts=$THIS_DIR/xeus-python-shell-libuv/xeus_python_shell/:/lib/python3.13/site-packages/xeus_python_shell/ - name: Upload artifact From 1d5b86317c1a0dfa932100d7af8397ee93bca386 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 13:50:48 +0100 Subject: [PATCH 022/112] path --- environment-wasm-build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/environment-wasm-build.yml b/environment-wasm-build.yml index 617bf918..59cec0e7 100644 --- a/environment-wasm-build.yml +++ b/environment-wasm-build.yml @@ -13,3 +13,5 @@ dependencies: - jupyterlite-core >0.6 - jupyter_server - jupyterlite-xeus + - # widgets + - ipywidgets \ No newline at end of file From 1b691293a5968dce1cbdcbab8c9c5933226cd734 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 19 Dec 2025 14:12:40 +0100 Subject: [PATCH 023/112] widgets --- environment-wasm-host.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/environment-wasm-host.yml b/environment-wasm-host.yml index 0c3a1034..9004a4a5 100644 --- a/environment-wasm-host.yml +++ b/environment-wasm-host.yml @@ -17,4 +17,6 @@ dependencies: - zstd - openssl - xz + - ipywidgets # - xeus-python-shell>=0.6.3 + From 88494df89a5acc451403669f01d6a5fbe31d68d2 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 11:34:32 +0100 Subject: [PATCH 024/112] build xeus-uv --- .github/workflows/main.yml | 19 +++++++++++++++++++ CMakeLists.txt | 2 +- environment-dev.yml | 2 +- src/main.cpp | 7 +++++-- src/xhook.cpp | 11 ++++++++--- src/xinterpreter.cpp | 5 ++--- src/xutils.cpp | 5 ++++- 7 files changed, 40 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c79417e8..0fec69dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,6 +32,25 @@ jobs: uses: mamba-org/setup-micromamba@v2 with: environment-file: environment-dev.yml + + - name: Install xeus-python-shell from GitHub + run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv + + - name: Checkout xeus-uv + uses: actions/checkout@v5 + with: + repository: jupyter-xeus/xeus-uv + path: xeus-uv + + - name: Build and install xeus-uv + run: | + mkdir xeus-uv/build + cd xeus-uv/build + cmake .. \ + -D CMAKE_PREFIX_PATH=$CONDA_PREFIX \ + -D CMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ + -D CMAKE_INSTALL_LIBDIR=lib + make -j 2 install - name: Make build directory run: mkdir build diff --git a/CMakeLists.txt b/CMakeLists.txt index 72053244..232e118a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ set(pybind11_REQUIRED_VERSION 2.6.1) set(pybind11_json_REQUIRED_VERSION 0.2.8) set(pyjs_REQUIRED_VERSION 2.0.0) -find_package(Python COMPONENTS Interpreter REQUIRED) +# find_package(Python COMPONENTS Interpreter REQUIRED) if (NOT TARGET pybind11::headers) # Defaults to ON for cmake >= 3.18 diff --git a/environment-dev.yml b/environment-dev.yml index 1cef1590..52dc8f9d 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -15,7 +15,7 @@ dependencies: # The debugger is not available with python 3.13 because # of a spurious bug in debugpy - python <3.13 - - xeus-python-shell>=0.6.3,<0.7 + #- xeus-python-shell>=0.6.3,<0.7 # we need an unreleased version - debugpy>=1.6.5 - libuvw - ipython diff --git a/src/main.cpp b/src/main.cpp index f1bf3733..78113373 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,11 +100,12 @@ int main(int argc, char* argv[]) // Instantiating the Python interpreter py::scoped_interpreter guard{}; + py::gil_scoped_acquire acquire; uv_loop_t* uv_loop_ptr{ nullptr }; { - py::gil_scoped_acquire acquire; + //py::gil_scoped_acquire acquire; // Create a uvloop and get pointer to the loop py::module asyncio = py::module::import("asyncio"); @@ -212,8 +213,10 @@ int main(int argc, char* argv[]) "If you want to connect to this kernel from an other client, you can use" " the " + connection_filename + " file." << std::endl; - + + std::cout << "Starting kernel..." << std::endl; kernel.start(); + std::cout << "Kernel stopped." << std::endl; } else { diff --git a/src/xhook.cpp b/src/xhook.cpp index 5fcf2db1..7ea8da32 100644 --- a/src/xhook.cpp +++ b/src/xhook.cpp @@ -24,7 +24,10 @@ namespace xpyt { hook::~hook() { - delete p_acquire; + if (p_acquire){ + delete p_acquire; + p_acquire = nullptr; + } } void hook::pre_hook_impl() @@ -37,8 +40,10 @@ namespace xpyt void hook::post_hook_impl() { - delete p_acquire; - p_acquire = nullptr; + if (p_acquire){ + delete p_acquire; + p_acquire = nullptr; + } } void hook::run_impl(std::shared_ptr /* loop */) diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index e7402a38..42f074ce 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -140,14 +140,12 @@ namespace xpyt std::vector traceback; - - - auto when_done_callback_lambda = [this, cb, config, user_expressions]() { py::gil_scoped_acquire acquire; // Placeholder for any actions to perform when execution is done + // Get payload nl::json payload = this->m_ipython_shell.attr("payload_manager").attr("read_payload")(); @@ -362,6 +360,7 @@ namespace xpyt void interpreter::shutdown_request_impl() { + std::cout<<"Shutting down interpreter..."< Date: Wed, 14 Jan 2026 11:44:38 +0100 Subject: [PATCH 025/112] add uvloop --- environment-dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment-dev.yml b/environment-dev.yml index 52dc8f9d..3971c2b9 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -18,6 +18,7 @@ dependencies: #- xeus-python-shell>=0.6.3,<0.7 # we need an unreleased version - debugpy>=1.6.5 - libuvw + - uvloop - ipython # Test dependencies - pytest From 6fcedf21c6dad62a7a5908419d92efc400c17e36 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 11:48:46 +0100 Subject: [PATCH 026/112] debugger --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 78113373..457b66e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -204,9 +204,9 @@ int main(int argc, char* argv[]) make_xserver, std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, - xeus::make_file_logger(xeus::xlogger::content, "xeus.log"))); - // xpyt::make_python_debugger, - // debugger_config); + xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), + xpyt::make_python_debugger, + debugger_config); std::clog << "Starting xeus-python kernel...\n\n" From f992408f11870f15915a3baf0a6528927aa95ff9 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 11:53:49 +0100 Subject: [PATCH 027/112] debugger --- .github/workflows/main.yml | 21 +++++++++++++++++++++ src/xutils.cpp | 3 +-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0fec69dd..57e0be89 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -116,6 +116,27 @@ jobs: - name: Make build directory run: mkdir build + + - name: Install xeus-python-shell from GitHub + run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv + + - name: Checkout xeus-uv + uses: actions/checkout@v5 + with: + repository: jupyter-xeus/xeus-uv + path: xeus-uv + + - name: Build and install xeus-uv + shell: cmd /C call {0} + run: | + mkdir xeus-uv\build + cd xeus-uv\build + cmake .. ^ + -GNinja ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" ^ + -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%\Library" + ninja install - name: Static build option if: matrix.build_type == 'static_build' diff --git a/src/xutils.cpp b/src/xutils.cpp index 8ecb4d5b..9d5b1a87 100644 --- a/src/xutils.cpp +++ b/src/xutils.cpp @@ -104,8 +104,7 @@ namespace xpyt void sigkill_handler(int /*sig*/) { std::cout << "Received termination signal. Exiting..." << std::endl; - // make sure to aquire the gil before exiting - //exit(0); + exit(0); } void print_pythonhome() From 3ec1f4eab18c317299705f3d90ad7b04ae324fb7 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 11:55:51 +0100 Subject: [PATCH 028/112] remove xeus-uv after building --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57e0be89..629d8700 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,6 +51,8 @@ jobs: -D CMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ -D CMAKE_INSTALL_LIBDIR=lib make -j 2 install + cd ../.. + rm -rf xeus-uv - name: Make build directory run: mkdir build @@ -137,6 +139,8 @@ jobs: -DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" ^ -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%\Library" ninja install + cd ../.. + rm -rf xeus-uv - name: Static build option if: matrix.build_type == 'static_build' From f0641385a1b875d9c664d5c3714947510d230dd7 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 11:59:19 +0100 Subject: [PATCH 029/112] special win env --- .github/workflows/main.yml | 2 +- environment-dev-win.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 environment-dev-win.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 629d8700..2a4ebfba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -114,7 +114,7 @@ jobs: uses: mamba-org/setup-micromamba@v2 with: init-shell: cmd.exe - environment-file: environment-dev.yml + environment-file: environment-dev-win.yml - name: Make build directory run: mkdir build diff --git a/environment-dev-win.yml b/environment-dev-win.yml new file mode 100644 index 00000000..f8e1adea --- /dev/null +++ b/environment-dev-win.yml @@ -0,0 +1,30 @@ +name: xeus-python +channels: + - conda-forge +dependencies: + # Build dependencies + - cmake + - cxx-compiler + - ninja + - cmake < 4 # TODO: remove pin on CMake + # Host dependencies + - xeus-zmq>=3.1,<4.0 + - nlohmann_json=3.12.0 + - pybind11>=2.6.1,<3.0 + - pybind11_json>=0.2.6,<0.3 + # The debugger is not available with python 3.13 because + # of a spurious bug in debugpy + - python <3.13 + #- xeus-python-shell>=0.6.3,<0.7 # we need an unreleased version + - debugpy>=1.6.5 + - libuvw + - ipython + # Test dependencies + - pytest + - nbval + - ipympl + - jupyter_kernel_test<0.8 + - doctest + - pluggy=1.3 + - pip: + - uvloop From f7d070782abfb69a822b12fcdb700926834fea60 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 12:17:02 +0100 Subject: [PATCH 030/112] use winloop --- environment-dev-win.yml | 3 +-- src/main.cpp | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/environment-dev-win.yml b/environment-dev-win.yml index f8e1adea..8a52d5b5 100644 --- a/environment-dev-win.yml +++ b/environment-dev-win.yml @@ -26,5 +26,4 @@ dependencies: - jupyter_kernel_test<0.8 - doctest - pluggy=1.3 - - pip: - - uvloop + - winloop \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 457b66e1..dedb2074 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,7 +109,12 @@ int main(int argc, char* argv[]) // Create a uvloop and get pointer to the loop py::module asyncio = py::module::import("asyncio"); + // ifdef for **not win** +#ifdef _WIN32 + py::module uvloop = py::module::import("winloop"); +#else py::module uvloop = py::module::import("uvloop"); +#endif py::object loop = uvloop.attr("new_event_loop")(); asyncio.attr("set_event_loop")(loop); From 3c93e82d87f9a3f8291f55203e84b1e99878ec83 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 12:30:40 +0100 Subject: [PATCH 031/112] debug --- src/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index dedb2074..75101e86 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,15 +127,18 @@ int main(int argc, char* argv[]) { throw std::runtime_error("Failed to get uvloop pointer"); } - + std::cout<<"casting to uv_loop_t*"<(raw_ptr); + } if (!uv_loop_ptr) { throw std::runtime_error("Failed to get libuv loop pointer"); } + std::cout<<"create loop from ptr "<< uv_loop_ptr < Date: Wed, 14 Jan 2026 12:32:37 +0100 Subject: [PATCH 032/112] move --- include/xeus-python/xhook.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp index 033edc16..a3ed9ac7 100644 --- a/include/xeus-python/xhook.hpp +++ b/include/xeus-python/xhook.hpp @@ -30,8 +30,7 @@ namespace py = pybind11; namespace xpyt { - XEUS_PYTHON_API - class hook : public xeus::xhook_base + class XEUS_PYTHON_API hook : public xeus::xhook_base { public: From 6f93c42ff8af51a28c730ef1e74008e4dd3af520 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Wed, 14 Jan 2026 12:46:18 +0100 Subject: [PATCH 033/112] debug --- src/xinterpreter_raw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index 0282f454..51773adf 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -277,7 +277,7 @@ namespace xpyt nl::json raw_interpreter::kernel_info_request_impl() { - + std::cout<<"raw_interpreter::kernel_info_request_impl()"< Date: Thu, 15 Jan 2026 10:25:21 +0100 Subject: [PATCH 034/112] native runner --- .github/workflows/main.yml | 17 ---- CMakeLists.txt | 9 +-- environment-dev-win.yml | 29 ------- environment-dev.yml | 2 - include/xeus-python/xasync_runner.hpp | 51 ++++++++++++ include/xeus-python/xhook.hpp | 51 ------------ src/main.cpp | 88 ++++++++++---------- src/xasync_runner.cpp | 112 ++++++++++++++++++++++++++ src/xhook.cpp | 56 ------------- 9 files changed, 212 insertions(+), 203 deletions(-) delete mode 100644 environment-dev-win.yml create mode 100644 include/xeus-python/xasync_runner.hpp delete mode 100644 include/xeus-python/xhook.hpp create mode 100644 src/xasync_runner.cpp delete mode 100644 src/xhook.cpp diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a4ebfba..69bfec5d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,23 +36,6 @@ jobs: - name: Install xeus-python-shell from GitHub run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv - - name: Checkout xeus-uv - uses: actions/checkout@v5 - with: - repository: jupyter-xeus/xeus-uv - path: xeus-uv - - - name: Build and install xeus-uv - run: | - mkdir xeus-uv/build - cd xeus-uv/build - cmake .. \ - -D CMAKE_PREFIX_PATH=$CONDA_PREFIX \ - -D CMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ - -D CMAKE_INSTALL_LIBDIR=lib - make -j 2 install - cd ../.. - rm -rf xeus-uv - name: Make build directory run: mkdir build diff --git a/CMakeLists.txt b/CMakeLists.txt index 232e118a..a197a96f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,9 +106,6 @@ else () find_package(xeus-zmq ${xeus-zmq_REQUIRED_VERSION} REQUIRED) endif () - find_package(xeus-uv REQUIRED) - find_library(UVW_LIBRARY uvw) - find_path(UVW_INCLUDE_DIR uvw.hpp) endif() @@ -169,7 +166,6 @@ set(XEUS_PYTHON_SRC src/xdebugpy_client.cpp src/xdisplay.cpp src/xdisplay.hpp - src/xhook.cpp src/xinput.cpp src/xinput.hpp src/xinspect.cpp @@ -185,6 +181,7 @@ set(XEUS_PYTHON_SRC src/xstream.hpp src/xtraceback.cpp src/xutils.cpp + src/xasync_runner.cpp ) set(XEUS_PYTHON_HEADERS @@ -195,7 +192,7 @@ set(XEUS_PYTHON_HEADERS include/xeus-python/xinterpreter_raw.hpp include/xeus-python/xtraceback.hpp include/xeus-python/xutils.hpp - include/xeus-python/xhook.hpp + include/xeus-python/xasync_runner.hpp ) set(XPYTHON_SRC @@ -382,7 +379,7 @@ endif () if (XPYT_BUILD_XPYTHON_EXECUTABLE) add_executable(xpython ${XPYTHON_SRC}) - target_link_libraries(xpython PRIVATE xeus-uv pybind11::embed ) + target_link_libraries(xpython PRIVATE pybind11::embed ) xpyt_set_common_options(xpython) xpyt_set_kernel_options(xpython) diff --git a/environment-dev-win.yml b/environment-dev-win.yml deleted file mode 100644 index 8a52d5b5..00000000 --- a/environment-dev-win.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: xeus-python -channels: - - conda-forge -dependencies: - # Build dependencies - - cmake - - cxx-compiler - - ninja - - cmake < 4 # TODO: remove pin on CMake - # Host dependencies - - xeus-zmq>=3.1,<4.0 - - nlohmann_json=3.12.0 - - pybind11>=2.6.1,<3.0 - - pybind11_json>=0.2.6,<0.3 - # The debugger is not available with python 3.13 because - # of a spurious bug in debugpy - - python <3.13 - #- xeus-python-shell>=0.6.3,<0.7 # we need an unreleased version - - debugpy>=1.6.5 - - libuvw - - ipython - # Test dependencies - - pytest - - nbval - - ipympl - - jupyter_kernel_test<0.8 - - doctest - - pluggy=1.3 - - winloop \ No newline at end of file diff --git a/environment-dev.yml b/environment-dev.yml index 3971c2b9..bc6e94ee 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -17,8 +17,6 @@ dependencies: - python <3.13 #- xeus-python-shell>=0.6.3,<0.7 # we need an unreleased version - debugpy>=1.6.5 - - libuvw - - uvloop - ipython # Test dependencies - pytest diff --git a/include/xeus-python/xasync_runner.hpp b/include/xeus-python/xasync_runner.hpp new file mode 100644 index 00000000..7a4d619e --- /dev/null +++ b/include/xeus-python/xasync_runner.hpp @@ -0,0 +1,51 @@ +/*************************************************************************** +* Copyright (c) 2024, Isabel Paredes * +* Copyright (c) 2024, QuantStack * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef XEUS_PYTHON_ASYNC_RUNNER_HPP +#define XEUS_PYTHON_ASYNC_RUNNER_HPP + +#include + +#include "xeus-python/xeus_python_config.hpp" +#include "xeus-zmq/xshell_runner.hpp" + + +namespace xpyt +{ + + class XEUS_PYTHON_API xasync_runner final : public xeus::xshell_runner + { + public: + + xasync_runner(); + + xasync_runner(const xasync_runner&) = delete; + xasync_runner& operator=(const xasync_runner&) = delete; + xasync_runner(xasync_runner&&) = delete; + xasync_runner& operator=(xasync_runner&&) = delete; + + ~xasync_runner() override = default; + + private: + void on_message_doorbell_shell(); + void on_message_doorbell_controller(); + + void run_impl() override; + + + }; + + + + + + +} // namespace xeus + +#endif // XEUS_PYTHON_ASYNC_RUNNER_HPP diff --git a/include/xeus-python/xhook.hpp b/include/xeus-python/xhook.hpp deleted file mode 100644 index a3ed9ac7..00000000 --- a/include/xeus-python/xhook.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** -* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * -* Wolf Vollprecht * -* Copyright (c) 2018, QuantStack -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XPYT_HOOK_HPP -#define XPYT_HOOK_HPP - -// pybind11 code internally forces hidden visibility on all internal code, but -// if non-hidden (and thus exported) code attempts to include a pybind type -// this warning occurs: -// 'xpyt::hook' declared with greater visibility than the type of its -// field 'xpyt::hook::p_acquire' [-Wattributes] -#ifdef __GNUC__ - #pragma GCC diagnostic ignored "-Wattributes" -#endif - -#include "xeus-python/xeus_python_config.hpp" -#include "xeus-uv/xhook_base.hpp" - -#include "pybind11/embed.h" -#include "pybind11/pybind11.h" - -namespace py = pybind11; - -namespace xpyt -{ - class XEUS_PYTHON_API hook : public xeus::xhook_base - { - public: - - hook() = default; - virtual ~hook(); - - private: - - void pre_hook_impl() override; - void post_hook_impl() override; - void run_impl(std::shared_ptr loop) override; - - py::gil_scoped_acquire* p_acquire{ nullptr}; - }; - -} - -#endif diff --git a/src/main.cpp b/src/main.cpp index 75101e86..14f12fb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,7 +48,11 @@ #include "xeus-python/xpaths.hpp" #include "xeus-python/xeus_python_config.hpp" #include "xeus-python/xutils.hpp" -#include "xeus-python/xhook.hpp" + + +#include "xeus-python/xasync_runner.hpp" +#include "xeus-zmq/xcontrol_default_runner.hpp" +#include "xeus-zmq/xserver_zmq_split.hpp" namespace py = pybind11; @@ -102,43 +106,7 @@ int main(int argc, char* argv[]) py::scoped_interpreter guard{}; py::gil_scoped_acquire acquire; - uv_loop_t* uv_loop_ptr{ nullptr }; - - { - //py::gil_scoped_acquire acquire; - - // Create a uvloop and get pointer to the loop - py::module asyncio = py::module::import("asyncio"); - // ifdef for **not win** -#ifdef _WIN32 - py::module uvloop = py::module::import("winloop"); -#else - py::module uvloop = py::module::import("uvloop"); -#endif - py::object loop = uvloop.attr("new_event_loop")(); - asyncio.attr("set_event_loop")(loop); - - std::cout<<"getting uv loop pointer from uvloop"<(raw_ptr); - - } - if (!uv_loop_ptr) - { - throw std::runtime_error("Failed to get libuv loop pointer"); - } - std::cout<<"create loop from ptr "<< uv_loop_ptr <(); + + + + + + // auto make_xserver = [&](xeus::xcontext& context, + // const xeus::xconfiguration& config, + // nl::json::error_handler_t eh) { + // return xeus::make_xserver_uv(context, config, eh, loop_ptr, std::move(py_hook)); + // }; + + + + + // create the runner by hand + - auto make_xserver = [&](xeus::xcontext& context, - const xeus::xconfiguration& config, - nl::json::error_handler_t eh) { - return xeus::make_xserver_uv(context, config, eh, loop_ptr, std::move(py_hook)); + + auto make_xserver = []( + xeus::xcontext& context, + const xeus::xconfiguration& config, + nl::json::error_handler_t eh) + { + std::unique_ptr async_runner = std::make_unique(); + + return xeus::make_xserver_shell + ( + context, + config, + eh, + std::make_unique(), + std::move(async_runner) + ); }; + + + + + + + + + if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp new file mode 100644 index 00000000..a7f482dd --- /dev/null +++ b/src/xasync_runner.cpp @@ -0,0 +1,112 @@ +/*************************************************************************** +* Copyright (c) 2024, Isabel Paredes * +* Copyright (c) 2024, QuantStack * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#include +#include + +#include "xeus-python/xasync_runner.hpp" +#include "pybind11/embed.h" +#include "pybind11/pybind11.h" + +namespace py = pybind11; + +namespace xpyt +{ + + xasync_runner::xasync_runner() + : xeus::xshell_runner() + { + } + + void xasync_runner::run_impl() + { + + //the file descriptor for the shell and controller sockets + // and create (libuv) poll handles to bind them to the loop + + auto fd_shell = this->get_shell_fd(); + auto fd_controller = this-> get_shell_controller_fd(); + + + + + + + // cast to integers + int fd_shell_int = static_cast(fd_shell); + int fd_controller_int = static_cast(fd_controller); + + + + + // wrap this->on_message_doorbell_shell and this->on_message_doorbell_controller + // into a py::cpp_function + py::cpp_function shell_callback = py::cpp_function([this]() { + this->on_message_doorbell_shell(); + }); + py::cpp_function controller_callback = py::cpp_function([this]() { + this->on_message_doorbell_controller(); + }); + + + + // Or create via exec if you need a more complex function: + py::exec(R"( + import asyncio + def run_main(fd_shell, fd_controller, shell_callback, controller_callback): + + # here we create / ensure we have an event loop + loop = asyncio.get_event_loop() + + loop.add_reader(fd_shell, shell_callback) + loop.add_reader(fd_controller, controller_callback) + + loop.run_forever() + + )", py::globals()); + + py::object run_func = py::globals()["run_main"]; + run_func(fd_shell_int, fd_controller_int, shell_callback, controller_callback); + + + } + + void xasync_runner::on_message_doorbell_shell() + { + std::cout << "Shell doorbell received!" << std::endl; + int ZMQ_DONTWAIT{ 1 }; // from zmq.h + while (auto msg = read_shell(ZMQ_DONTWAIT)) + { + notify_shell_listener(std::move(msg.value())); + } + } + + void xasync_runner::on_message_doorbell_controller() + { + std::cout << "Controller doorbell received!" << std::endl; + int ZMQ_DONTWAIT{ 1 }; // from zmq.h + while (auto msg = read_controller(ZMQ_DONTWAIT)) + { + std::string val{ msg.value() }; + if (val == "stop") + { + send_controller(std::move(val)); + //p_loop->stop(); // TODO + } + else + { + std::string rep = notify_internal_listener(std::move(val)); + send_controller(std::move(rep)); + } + } + } + + + +} // namespace xpyt diff --git a/src/xhook.cpp b/src/xhook.cpp deleted file mode 100644 index 7ea8da32..00000000 --- a/src/xhook.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** -* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * -* Wolf Vollprecht * -* Copyright (c) 2018, QuantStack -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef UVW_AS_LIB -#define UVW_AS_LIB -#include -#endif - -#include "xeus-python/xhook.hpp" - -#include "pybind11/embed.h" -#include "pybind11/pybind11.h" - -namespace py = pybind11; - -namespace xpyt -{ - hook::~hook() - { - if (p_acquire){ - delete p_acquire; - p_acquire = nullptr; - } - } - - void hook::pre_hook_impl() - { - if (!p_acquire) - { - p_acquire = new py::gil_scoped_acquire(); - } - } - - void hook::post_hook_impl() - { - if (p_acquire){ - delete p_acquire; - p_acquire = nullptr; - } - } - - void hook::run_impl(std::shared_ptr /* loop */) - { - py::gil_scoped_acquire acquire; - py::module asyncio = py::module::import("asyncio"); - py::object loop = asyncio.attr("get_event_loop")(); - loop.attr("run_forever")(); - } -} From e653348a6d91024b7eccfe21b3110b813a6d6b95 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 10:32:29 +0100 Subject: [PATCH 035/112] native runner --- src/xasync_runner.cpp | 44 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index a7f482dd..6d81023c 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -27,23 +27,9 @@ namespace xpyt void xasync_runner::run_impl() { - //the file descriptor for the shell and controller sockets - // and create (libuv) poll handles to bind them to the loop - - auto fd_shell = this->get_shell_fd(); - auto fd_controller = this-> get_shell_controller_fd(); - - - - - - - // cast to integers - int fd_shell_int = static_cast(fd_shell); - int fd_controller_int = static_cast(fd_controller); - - + int fd_shell_int = static_cast(this->get_shell_fd()); + int fd_controller_int = static_cast(this-> get_shell_controller_fd()); // wrap this->on_message_doorbell_shell and this->on_message_doorbell_controller // into a py::cpp_function @@ -97,7 +83,31 @@ namespace xpyt if (val == "stop") { send_controller(std::move(val)); - //p_loop->stop(); // TODO + + + + int fd_shell_int = static_cast(this->get_shell_fd()); + int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + + + // Or create via exec if you need a more complex function: + py::exec(R"( + import asyncio + def stop_loop(fd_shell, fd_controller): + + # here we create / ensure we have an event loop + loop = asyncio.get_event_loop() + + loop.remove_reader(fd_shell) + loop.remove_reader(fd_controller) + + loop.stop() + + )", py::globals()); + + py::object stop_func = py::globals()["stop_loop"]; + stop_func(fd_shell_int, fd_controller_int); + } else { From 996ffce61d8c4c674b1258dd5c0ab9c6e93a8d33 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 10:33:59 +0100 Subject: [PATCH 036/112] native runner --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69bfec5d..d4269ed7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -97,7 +97,7 @@ jobs: uses: mamba-org/setup-micromamba@v2 with: init-shell: cmd.exe - environment-file: environment-dev-win.yml + environment-file: environment-dev.yml - name: Make build directory run: mkdir build From 4ebb63599740845adf68840a143657cd4e201f8b Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 10:34:08 +0100 Subject: [PATCH 037/112] native runner --- .github/workflows/main.yml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d4269ed7..66cee2e6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,25 +105,6 @@ jobs: - name: Install xeus-python-shell from GitHub run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv - - name: Checkout xeus-uv - uses: actions/checkout@v5 - with: - repository: jupyter-xeus/xeus-uv - path: xeus-uv - - - name: Build and install xeus-uv - shell: cmd /C call {0} - run: | - mkdir xeus-uv\build - cd xeus-uv\build - cmake .. ^ - -GNinja ^ - -DCMAKE_BUILD_TYPE=Release ^ - -DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" ^ - -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%\Library" - ninja install - cd ../.. - rm -rf xeus-uv - name: Static build option if: matrix.build_type == 'static_build' From 3cde4bbaa940c1ec84876da63e8dfcdcaf03e11d Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 10:41:52 +0100 Subject: [PATCH 038/112] remove uv --- src/main.cpp | 7 ------- src/xasync_runner.cpp | 2 -- 2 files changed, 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 14f12fb2..284eba90 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,10 +21,6 @@ #include #endif -#ifndef UVW_AS_LIB -#define UVW_AS_LIB -#include -#endif #include "xeus/xkernel.hpp" #include "xeus/xkernel_configuration.hpp" @@ -35,9 +31,6 @@ #include "xeus-zmq/xzmq_context.hpp" -#include "xeus-uv/xserver_uv.hpp" -#include "xeus-uv/xhook_base.hpp" - #include "pybind11/embed.h" #include "pybind11/pybind11.h" diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 6d81023c..60f5e1b2 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -41,8 +41,6 @@ namespace xpyt }); - - // Or create via exec if you need a more complex function: py::exec(R"( import asyncio def run_main(fd_shell, fd_controller, shell_callback, controller_callback): From 30484fb464cbb7caa652a6b0848c43d13022b22f Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 11:21:35 +0100 Subject: [PATCH 039/112] fix debugger bug --- src/xasync_runner.cpp | 2 ++ src/xdebugger.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 60f5e1b2..6170a04c 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -78,6 +78,8 @@ namespace xpyt while (auto msg = read_controller(ZMQ_DONTWAIT)) { std::string val{ msg.value() }; + + std::cout << "Controller message: " << val << std::endl; if (val == "stop") { send_controller(std::move(val)); diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index f6a6624b..6491810e 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -288,9 +288,10 @@ namespace xpyt py::module xeus_python_shell = py::module::import("xeus_python_shell.debugger"); m_pydebugger = xeus_python_shell.attr("XDebugger")(); - // Get debugpy version - std::string expression = "debugpy.__version__"; - std::string version = (eval(py::str(expression))).cast(); + // Import debugpy module and get version + py::module debugpy = py::module::import("debugpy"); + std::string version = debugpy.attr("__version__").cast(); + // Format the version to match [0-9]+(\s[0-9]+)* size_t pos = version.find_first_of("abrc"); From 762d3e95c27fe5531f0649aae57fa473237ce536 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 12:03:04 +0100 Subject: [PATCH 040/112] fix raw kernel --- include/xeus-python/xinterpreter_raw.hpp | 4 ++ src/xinterpreter_raw.cpp | 50 ++++++++++++++++++------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/include/xeus-python/xinterpreter_raw.hpp b/include/xeus-python/xinterpreter_raw.hpp index 3305e072..9630cfb5 100644 --- a/include/xeus-python/xinterpreter_raw.hpp +++ b/include/xeus-python/xinterpreter_raw.hpp @@ -88,6 +88,10 @@ namespace xpyt bool m_release_gil_at_startup = true; gil_scoped_release_ptr m_release_gil = nullptr; bool m_redirect_display_enabled; + + std::string _i; + std::string _ii; + std::string _iii; }; } diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index 51773adf..055c42ee 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -53,6 +53,7 @@ namespace xpyt { redirect_output(); } + m_release_gil_at_startup = false; } raw_interpreter::~raw_interpreter() @@ -61,6 +62,7 @@ namespace xpyt void raw_interpreter::configure_impl() { + std::cout<<"raw_interpreter::configure_impl()"<()); + // When the debugger is started, it send some python code to execute, that triggers + // a call to publish_stream, and ultimately to this function. However: + // - we are out of the handling of an execute_request, therefore set_request_context + // has not been called + // - we cannot set it from another thread (the context of the context variable would + // be different) + // Therefore, we have to catch the exception thrown when the context variable is empty. + try + { + py::object res = context_module.attr("get_request_context")(); + return *(res.cast()); + } + catch (py::error_already_set& e) + { + return empty_request_context; + } } - void raw_interpreter::redirect_output() { py::module sys = py::module::import("sys"); From 72bbf9265b3bec7e6c89e0b65237841df84dba79 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 12:09:46 +0100 Subject: [PATCH 041/112] fix raw kernel --- include/xeus-python/xinterpreter_raw.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/xeus-python/xinterpreter_raw.hpp b/include/xeus-python/xinterpreter_raw.hpp index 9630cfb5..0bdebfd6 100644 --- a/include/xeus-python/xinterpreter_raw.hpp +++ b/include/xeus-python/xinterpreter_raw.hpp @@ -89,9 +89,7 @@ namespace xpyt gil_scoped_release_ptr m_release_gil = nullptr; bool m_redirect_display_enabled; - std::string _i; - std::string _ii; - std::string _iii; + std::string _i,_ii,_iii; }; } From c6bca8a0ba9a74be22abb4a91c52a662f87f98c5 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 12:42:41 +0100 Subject: [PATCH 042/112] use one global dict --- include/xeus-python/xinterpreter_raw.hpp | 2 ++ src/xinspect.cpp | 30 ++++++++++----------- src/xinspect.hpp | 8 +++--- src/xinterpreter_raw.cpp | 33 +++++++++++++----------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/include/xeus-python/xinterpreter_raw.hpp b/include/xeus-python/xinterpreter_raw.hpp index 0bdebfd6..9760cba3 100644 --- a/include/xeus-python/xinterpreter_raw.hpp +++ b/include/xeus-python/xinterpreter_raw.hpp @@ -90,6 +90,8 @@ namespace xpyt bool m_redirect_display_enabled; std::string _i,_ii,_iii; + + py::dict m_global_dict; }; } diff --git a/src/xinspect.cpp b/src/xinspect.cpp index c820ea9b..d7420a44 100644 --- a/src/xinspect.cpp +++ b/src/xinspect.cpp @@ -22,30 +22,30 @@ using namespace pybind11::literals; namespace xpyt { - py::object static_inspect(const std::string& code) + py::object static_inspect(const std::string& code, py::dict globals) { py::module jedi = py::module::import("jedi"); - return jedi.attr("Interpreter")(code, py::make_tuple(py::globals())); + return jedi.attr("Interpreter")(code, py::make_tuple(globals)); } - py::object static_inspect(const std::string& code, int cursor_pos) + + py::object static_inspect(const std::string& code, int cursor_pos, py::dict globals) { - std::string sub_code = code.substr(0, cursor_pos); - return static_inspect(sub_code); + py::module jedi = py::module::import("jedi"); + return jedi.attr("Interpreter")(code, cursor_pos, py::make_tuple(globals)); } - py::list get_completions(const std::string& code, int cursor_pos) + + py::list get_completions(const std::string& code, int cursor_pos, py::dict globals) { - return static_inspect(code, cursor_pos).attr("complete")(); + return static_inspect(code, cursor_pos, globals).attr("complete")(); } - py::list get_completions(const std::string& code) + py::list get_completions(const std::string& code, py::dict globals) { - return static_inspect(code).attr("complete")(); + return static_inspect(code, globals).attr("complete")(); } - py::list get_completions(const std::string& code); - std::string formatted_docstring_impl(py::object inter) { py::object definition = py::none(); @@ -121,15 +121,15 @@ namespace xpyt return result; } - std::string formatted_docstring(const std::string& code, int cursor_pos) + std::string formatted_docstring(const std::string& code, int cursor_pos, py::dict globals) { - py::object inter = static_inspect(code, cursor_pos); + py::object inter = static_inspect(code, cursor_pos, globals); return formatted_docstring_impl(inter); } - std::string formatted_docstring(const std::string& code) + std::string formatted_docstring(const std::string& code, py::dict globals) { - py::object inter = static_inspect(code); + py::object inter = static_inspect(code, globals); return formatted_docstring_impl(inter); } } diff --git a/src/xinspect.hpp b/src/xinspect.hpp index edd235da..b3fa6a77 100644 --- a/src/xinspect.hpp +++ b/src/xinspect.hpp @@ -19,11 +19,11 @@ namespace py = pybind11; namespace xpyt { - py::list get_completions(const std::string& code, int cursor_pos); - py::list get_completions(const std::string& code); + py::list get_completions(const std::string& code, int cursor_pos, py::dict globals); + py::list get_completions(const std::string& code, py::dict globals); - std::string formatted_docstring(const std::string& code, int cursor_pos); - std::string formatted_docstring(const std::string& code); + std::string formatted_docstring(const std::string& code, int cursor_pos, py::dict globals); + std::string formatted_docstring(const std::string& code, py::dict globals); } #endif diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index 055c42ee..a852c6fe 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -48,6 +48,7 @@ namespace xpyt raw_interpreter::raw_interpreter(bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/) :m_redirect_display_enabled{ redirect_display_enabled } { + m_global_dict = py::globals(); xeus::register_interpreter(this); if (redirect_output_enabled) { @@ -87,8 +88,8 @@ namespace xpyt } // Expose display functions to Python - py::globals()["display"] = display_module.attr("display"); - py::globals()["update_display"] = display_module.attr("update_display"); + m_global_dict["display"] = display_module.attr("display"); + m_global_dict["update_display"] = display_module.attr("update_display"); // Monkey patching "import IPython.core.display" sys.attr("modules")["IPython.core.display"] = display_module; @@ -100,9 +101,13 @@ namespace xpyt sys.attr("modules")["IPython.core.getipython"] = kernel_module; // Add get_ipython to global namespace - py::globals()["get_ipython"] = kernel_module.attr("get_ipython"); + m_global_dict["get_ipython"] = kernel_module.attr("get_ipython"); kernel_module.attr("get_ipython")(); + std::cout<<"write globals _i, _ii, _iii"< matches; int cursor_start = cursor_pos; - py::list completions = get_completions(code, cursor_pos); + py::list completions = get_completions(code, cursor_pos, m_global_dict); if (py::len(completions) != 0) { @@ -264,7 +267,7 @@ namespace xpyt nl::json kernel_res; nl::json pub_data; - std::string docstring = formatted_docstring(code, cursor_pos); + std::string docstring = formatted_docstring(code, cursor_pos, m_global_dict); bool found = false; if (!docstring.empty()) From d81994063dc4394055b01e625b8b71204ed013ea Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 12:58:37 +0100 Subject: [PATCH 043/112] fixes --- src/xinspect.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xinspect.cpp b/src/xinspect.cpp index d7420a44..1d94635f 100644 --- a/src/xinspect.cpp +++ b/src/xinspect.cpp @@ -31,8 +31,8 @@ namespace xpyt py::object static_inspect(const std::string& code, int cursor_pos, py::dict globals) { - py::module jedi = py::module::import("jedi"); - return jedi.attr("Interpreter")(code, cursor_pos, py::make_tuple(globals)); + std::string sub_code = code.substr(0, cursor_pos); + return static_inspect(sub_code, globals); } From f157b1eea4df280ffa36adc1c96a8f5e39167048 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 13:45:08 +0100 Subject: [PATCH 044/112] time based win --- src/xasync_runner.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 6170a04c..02db9067 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -42,16 +42,42 @@ namespace xpyt py::exec(R"( + + import sys + is_win = sys.platform.startswith("win") + import asyncio - def run_main(fd_shell, fd_controller, shell_callback, controller_callback): + if is_win: + + async def loop_shell(fd_shell, shell_callback): + while True: + await asyncio.sleep(0.01) + shell_callback() + async def loop_controller(fd_controller, controller_callback): + while True: + await asyncio.sleep(0.01) + controller_callback() + + + def run_main(fd_shell, fd_controller, shell_callback, controller_callback): + + # here we create / ensure we have an event loop + loop = asyncio.get_event_loop() + + task_shell = loop.create_task(loop_shell(fd_shell, shell_callback)) + task_controller = loop.create_task(loop_controller(fd_controller, controller_callback)) + + loop.run_forever() + else: + def run_main(fd_shell, fd_controller, shell_callback, controller_callback): - # here we create / ensure we have an event loop - loop = asyncio.get_event_loop() + # here we create / ensure we have an event loop + loop = asyncio.get_event_loop() - loop.add_reader(fd_shell, shell_callback) - loop.add_reader(fd_controller, controller_callback) + loop.add_reader(fd_shell, shell_callback) + loop.add_reader(fd_controller, controller_callback) - loop.run_forever() + loop.run_forever() )", py::globals()); From ef0d671c9413195c5b454874ad936ed3bc24a500 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 13:54:15 +0100 Subject: [PATCH 045/112] time based win --- src/xasync_runner.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 02db9067..490cbea4 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -26,11 +26,13 @@ namespace xpyt void xasync_runner::run_impl() { - + std::cout << "get descriptors "<< std::endl; int fd_shell_int = static_cast(this->get_shell_fd()); int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + std::cout << "Got descriptors: " << fd_shell_int << ", " << fd_controller_int << std::endl; + // wrap this->on_message_doorbell_shell and this->on_message_doorbell_controller // into a py::cpp_function py::cpp_function shell_callback = py::cpp_function([this]() { @@ -44,7 +46,7 @@ namespace xpyt py::exec(R"( import sys - is_win = sys.platform.startswith("win") + is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") import asyncio if is_win: From 8e7be8638d3cf45704420b8253b7ecce05ebf14d Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 14:01:53 +0100 Subject: [PATCH 046/112] time based win --- src/xasync_runner.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 490cbea4..e790ab82 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -27,9 +27,14 @@ namespace xpyt void xasync_runner::run_impl() { std::cout << "get descriptors "<< std::endl; - - int fd_shell_int = static_cast(this->get_shell_fd()); - int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + #ifndef _WIN32 + int fd_shell_int = static_cast(this->get_shell_fd()); + int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + #else + // just use placeholders on Windows + int fd_shell_int = 0; + int fd_controller_int = 0; + #endif std::cout << "Got descriptors: " << fd_shell_int << ", " << fd_controller_int << std::endl; From e2e91b86991d3b55fd77cb08be76cf25907f80a7 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 14:08:36 +0100 Subject: [PATCH 047/112] first c++ tests --- .github/workflows/main.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 66cee2e6..ba9e1aaa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -139,11 +139,7 @@ jobs: set CL=/MP ninja install working-directory: build - - - name: Test xeus-python Python - shell: cmd /C call {0} - run: pytest . -vvv - + - name: Test xeus-python C++ shell: cmd /C call {0} run: | @@ -152,3 +148,9 @@ jobs: timeout-minutes: 4 working-directory: build\test + - name: Test xeus-python Python + shell: cmd /C call {0} + run: pytest . -s -vvv + + + From 6942240bb8da9def927637b3d78e7b1b364c41cd Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 14:21:20 +0100 Subject: [PATCH 048/112] remove activation --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ba9e1aaa..d3edff9e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -139,11 +139,10 @@ jobs: set CL=/MP ninja install working-directory: build - + - name: Test xeus-python C++ shell: cmd /C call {0} run: | - micromamba activate xeus-python test_xeus_python timeout-minutes: 4 working-directory: build\test From 85f110b61d908b4bb2ec589238ae8c67b7b45e58 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 14:29:31 +0100 Subject: [PATCH 049/112] remove activation --- src/xasync_runner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index e790ab82..b8eda039 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -22,6 +22,7 @@ namespace xpyt xasync_runner::xasync_runner() : xeus::xshell_runner() { + std::cout<< "xasync_runner created" << std::endl; } void xasync_runner::run_impl() From 659aa429f6be20b1225fbf5bc969029f7ac1bb66 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 14:31:03 +0100 Subject: [PATCH 050/112] remove activation --- src/xasync_runner.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index b8eda039..3377a652 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -127,13 +127,17 @@ namespace xpyt // Or create via exec if you need a more complex function: py::exec(R"( import asyncio + import sys + def stop_loop(fd_shell, fd_controller): + is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") + # here we create / ensure we have an event loop loop = asyncio.get_event_loop() - - loop.remove_reader(fd_shell) - loop.remove_reader(fd_controller) + if not is_win: + loop.remove_reader(fd_shell) + loop.remove_reader(fd_controller) loop.stop() From edcc4d91132f1d4e2b45db1031a1dc32eb774420 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 14:40:06 +0100 Subject: [PATCH 051/112] remove activation --- src/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 284eba90..5d56109a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -177,15 +177,14 @@ int main(int argc, char* argv[]) const xeus::xconfiguration& config, nl::json::error_handler_t eh) { - std::unique_ptr async_runner = std::make_unique(); - + std::cout << "Creating xserver_uv" << std::endl; return xeus::make_xserver_shell ( context, config, eh, std::make_unique(), - std::move(async_runner) + std::make_unique(); ); }; From ba03df8a3801d07c144352afb5db6b3b8c15e627 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Thu, 15 Jan 2026 14:44:07 +0100 Subject: [PATCH 052/112] remove activation --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5d56109a..6d924512 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) config, eh, std::make_unique(), - std::make_unique(); + std::make_unique() ); }; From 5148f51d59c505a5f376a3bb49dcc1a6788b6a7c Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 08:42:50 +0100 Subject: [PATCH 053/112] dont build extension --- .github/workflows/main.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d3edff9e..3e8e5df6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -127,7 +127,7 @@ jobs: -DXPYT_BUILD_TESTS=ON ^ -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%\Library" ^ -DXEXTRA_JUPYTER_DATA_DIR=%CONDA_PREFIX%\share\jupyter ^ - -DXPYT_BUILD_XPYTHON_EXTENSION=ON ^ + -DXPYT_BUILD_XPYTHON_EXTENSION=OFF ^ -DXEUS_PYTHONHOME_RELPATH=..\\ ^ -DCMAKE_CXX_FLAGS=/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING ^ ${{ env.CMAKE_EXTRA_ARGS }} @@ -140,6 +140,11 @@ jobs: ninja install working-directory: build + - name: Test xeus-python Python + shell: cmd /C call {0} + run: pytest . -s -vvv + + - name: Test xeus-python C++ shell: cmd /C call {0} run: | @@ -147,9 +152,6 @@ jobs: timeout-minutes: 4 working-directory: build\test - - name: Test xeus-python Python - shell: cmd /C call {0} - run: pytest . -s -vvv From 887888e480327e10259d1b09954839b9130472b1 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 08:45:54 +0100 Subject: [PATCH 054/112] use dummy in stop --- src/xasync_runner.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 3377a652..a2b6c233 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -49,6 +49,9 @@ namespace xpyt }); + // ensure gil + py::gil_scoped_acquire acquire; + py::exec(R"( import sys @@ -120,9 +123,17 @@ namespace xpyt - int fd_shell_int = static_cast(this->get_shell_fd()); - int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + std::cout << "get descriptors to stop"<< std::endl; + #ifndef _WIN32 + int fd_shell_int = static_cast(this->get_shell_fd()); + int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + #else + // just use placeholders on Windows + int fd_shell_int = 0; + int fd_controller_int = 0; + #endif + py::gil_scoped_acquire acquire; // Or create via exec if you need a more complex function: py::exec(R"( From c9debbb9ff5f82734382fd48321002c4200a32c3 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 08:56:46 +0100 Subject: [PATCH 055/112] activate --- .github/workflows/main.yml | 1 + environment-dev.yml | 1 + src/xinterpreter.cpp | 2 ++ 3 files changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3e8e5df6..8911734a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,6 +103,7 @@ jobs: run: mkdir build - name: Install xeus-python-shell from GitHub + shell: cmd /C call {0} run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv diff --git a/environment-dev.yml b/environment-dev.yml index bc6e94ee..7fc0d645 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -15,6 +15,7 @@ dependencies: # The debugger is not available with python 3.13 because # of a spurious bug in debugpy - python <3.13 + - pip #- xeus-python-shell>=0.6.3,<0.7 # we need an unreleased version - debugpy>=1.6.5 - ipython diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 42f074ce..c7103ebc 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -125,6 +125,7 @@ namespace xpyt xeus::execute_request_config config, nl::json user_expressions) { + std::cout<<"interpreter::execute_request_impl()"< Date: Fri, 16 Jan 2026 09:02:25 +0100 Subject: [PATCH 056/112] build extension again --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8911734a..fab5b9cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -128,7 +128,7 @@ jobs: -DXPYT_BUILD_TESTS=ON ^ -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%\Library" ^ -DXEXTRA_JUPYTER_DATA_DIR=%CONDA_PREFIX%\share\jupyter ^ - -DXPYT_BUILD_XPYTHON_EXTENSION=OFF ^ + -DXPYT_BUILD_XPYTHON_EXTENSION=ON ^ -DXEUS_PYTHONHOME_RELPATH=..\\ ^ -DCMAKE_CXX_FLAGS=/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING ^ ${{ env.CMAKE_EXTRA_ARGS }} From 3abd2f06a05f7a66f2de9b9c6e8b918638b4f70d Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 09:10:02 +0100 Subject: [PATCH 057/112] build extension again --- src/xasync_runner.cpp | 26 +++++++++++++------------- src/xinterpreter.cpp | 1 + src/xinterpreter_raw.cpp | 6 +++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index a2b6c233..69caf142 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -28,14 +28,14 @@ namespace xpyt void xasync_runner::run_impl() { std::cout << "get descriptors "<< std::endl; - #ifndef _WIN32 - int fd_shell_int = static_cast(this->get_shell_fd()); - int fd_controller_int = static_cast(this-> get_shell_controller_fd()); - #else + // #ifndef _WIN32 + // int fd_shell_int = static_cast(this->get_shell_fd()); + // int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + // #else // just use placeholders on Windows int fd_shell_int = 0; int fd_controller_int = 0; - #endif + // #endif std::cout << "Got descriptors: " << fd_shell_int << ", " << fd_controller_int << std::endl; @@ -58,7 +58,7 @@ namespace xpyt is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") import asyncio - if is_win: + if False: # is_win async def loop_shell(fd_shell, shell_callback): while True: @@ -124,14 +124,14 @@ namespace xpyt std::cout << "get descriptors to stop"<< std::endl; - #ifndef _WIN32 + //#ifndef _WIN32 int fd_shell_int = static_cast(this->get_shell_fd()); int fd_controller_int = static_cast(this-> get_shell_controller_fd()); - #else - // just use placeholders on Windows - int fd_shell_int = 0; - int fd_controller_int = 0; - #endif + // #else + // // just use placeholders on Windows + // int fd_shell_int = 0; + // int fd_controller_int = 0; + // #endif py::gil_scoped_acquire acquire; @@ -146,7 +146,7 @@ namespace xpyt # here we create / ensure we have an event loop loop = asyncio.get_event_loop() - if not is_win: + if True: loop.remove_reader(fd_shell) loop.remove_reader(fd_controller) diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index c7103ebc..4680fff5 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -184,6 +184,7 @@ namespace xpyt try { + m_ipython_shell.attr("run_cell_async")(code, when_done_callback, "store_history"_a=config.store_history, "silent"_a=config.silent); } catch(std::runtime_error& e) diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index a852c6fe..d9c7886c 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -105,9 +105,9 @@ namespace xpyt kernel_module.attr("get_ipython")(); std::cout<<"write globals _i, _ii, _iii"< Date: Fri, 16 Jan 2026 09:10:23 +0100 Subject: [PATCH 058/112] use reader --- src/xasync_runner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 69caf142..8a8303fa 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -29,12 +29,12 @@ namespace xpyt { std::cout << "get descriptors "<< std::endl; // #ifndef _WIN32 - // int fd_shell_int = static_cast(this->get_shell_fd()); - // int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + int fd_shell_int = static_cast(this->get_shell_fd()); + int fd_controller_int = static_cast(this-> get_shell_controller_fd()); // #else - // just use placeholders on Windows - int fd_shell_int = 0; - int fd_controller_int = 0; + // // just use placeholders on Windows + // int fd_shell_int = 0; + // int fd_controller_int = 0; // #endif std::cout << "Got descriptors: " << fd_shell_int << ", " << fd_controller_int << std::endl; From 090f5353610af0a5fe3b15ede5fd7a33f6f1bef4 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 09:17:36 +0100 Subject: [PATCH 059/112] use reader --- src/xasync_runner.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 8a8303fa..918d82f7 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -28,14 +28,14 @@ namespace xpyt void xasync_runner::run_impl() { std::cout << "get descriptors "<< std::endl; - // #ifndef _WIN32 + #ifndef _WIN32 int fd_shell_int = static_cast(this->get_shell_fd()); int fd_controller_int = static_cast(this-> get_shell_controller_fd()); - // #else - // // just use placeholders on Windows - // int fd_shell_int = 0; - // int fd_controller_int = 0; - // #endif + #else + // just use placeholders on Windows + int fd_shell_int = 0; + int fd_controller_int = 0; + #endif std::cout << "Got descriptors: " << fd_shell_int << ", " << fd_controller_int << std::endl; @@ -58,7 +58,7 @@ namespace xpyt is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") import asyncio - if False: # is_win + if is_win async def loop_shell(fd_shell, shell_callback): while True: @@ -124,14 +124,14 @@ namespace xpyt std::cout << "get descriptors to stop"<< std::endl; - //#ifndef _WIN32 + #ifndef _WIN32 int fd_shell_int = static_cast(this->get_shell_fd()); int fd_controller_int = static_cast(this-> get_shell_controller_fd()); - // #else - // // just use placeholders on Windows - // int fd_shell_int = 0; - // int fd_controller_int = 0; - // #endif + #else + // just use placeholders on Windows + int fd_shell_int = 0; + int fd_controller_int = 0; + #endif py::gil_scoped_acquire acquire; @@ -146,7 +146,7 @@ namespace xpyt # here we create / ensure we have an event loop loop = asyncio.get_event_loop() - if True: + if not is_win: loop.remove_reader(fd_shell) loop.remove_reader(fd_controller) From 428bb9f545d211699297fd5dfc3de5e1fa13039c Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 09:19:46 +0100 Subject: [PATCH 060/112] use reader --- src/xasync_runner.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 918d82f7..c5f448c9 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -100,17 +100,16 @@ namespace xpyt void xasync_runner::on_message_doorbell_shell() { - std::cout << "Shell doorbell received!" << std::endl; int ZMQ_DONTWAIT{ 1 }; // from zmq.h while (auto msg = read_shell(ZMQ_DONTWAIT)) { + std::cout << "Shell message: " << msg.value() << std::endl; notify_shell_listener(std::move(msg.value())); } } void xasync_runner::on_message_doorbell_controller() { - std::cout << "Controller doorbell received!" << std::endl; int ZMQ_DONTWAIT{ 1 }; // from zmq.h while (auto msg = read_controller(ZMQ_DONTWAIT)) { From 6059c301239dcc36e3aa38bbb5d6832888cbd46a Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 09:37:23 +0100 Subject: [PATCH 061/112] use reader --- src/xasync_runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index c5f448c9..04f340dc 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -103,7 +103,7 @@ namespace xpyt int ZMQ_DONTWAIT{ 1 }; // from zmq.h while (auto msg = read_shell(ZMQ_DONTWAIT)) { - std::cout << "Shell message: " << msg.value() << std::endl; + std::cout << "got message on shell doorbell:\n"< Date: Fri, 16 Jan 2026 09:39:37 +0100 Subject: [PATCH 062/112] fix --- src/xasync_runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 04f340dc..5f4ed8bb 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -103,7 +103,7 @@ namespace xpyt int ZMQ_DONTWAIT{ 1 }; // from zmq.h while (auto msg = read_shell(ZMQ_DONTWAIT)) { - std::cout << "got message on shell doorbell:\n"< Date: Fri, 16 Jan 2026 09:45:38 +0100 Subject: [PATCH 063/112] fix --- src/xasync_runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 5f4ed8bb..a9d1ba37 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -58,7 +58,7 @@ namespace xpyt is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") import asyncio - if is_win + if is_win: async def loop_shell(fd_shell, shell_callback): while True: From 5960c8263322b2fbf004cb47812e6fd3ff3e977c Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 09:56:45 +0100 Subject: [PATCH 064/112] fix --- src/xasync_runner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index a9d1ba37..798a7c53 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -64,10 +64,12 @@ namespace xpyt while True: await asyncio.sleep(0.01) shell_callback() + controller_callback() async def loop_controller(fd_controller, controller_callback): while True: await asyncio.sleep(0.01) controller_callback() + shell_callback() def run_main(fd_shell, fd_controller, shell_callback, controller_callback): From 7a1fa8f5b39dfe464b1eff3d49dcc45fa4bb7497 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 10:14:09 +0100 Subject: [PATCH 065/112] fix --- src/xdebugger.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index 6491810e..f6a6624b 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -288,10 +288,9 @@ namespace xpyt py::module xeus_python_shell = py::module::import("xeus_python_shell.debugger"); m_pydebugger = xeus_python_shell.attr("XDebugger")(); - // Import debugpy module and get version - py::module debugpy = py::module::import("debugpy"); - std::string version = debugpy.attr("__version__").cast(); - + // Get debugpy version + std::string expression = "debugpy.__version__"; + std::string version = (eval(py::str(expression))).cast(); // Format the version to match [0-9]+(\s[0-9]+)* size_t pos = version.find_first_of("abrc"); From 604613d1db7dbbf7a45ab43b041cb0a3937aac4d Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 10:53:47 +0100 Subject: [PATCH 066/112] fix --- include/xeus-python/xasync_runner.hpp | 8 +++- include/xeus-python/xdebugger.hpp | 10 ++++- include/xeus-python/xinterpreter.hpp | 6 ++- include/xeus-python/xinterpreter_raw.hpp | 4 +- src/main.cpp | 52 ++++++++++++++--------- src/xasync_runner.cpp | 13 +++--- src/xdebugger.cpp | 14 +++--- src/xinterpreter.cpp | 9 ++-- src/xinterpreter_raw.cpp | 10 +++-- src/xpython_extension.cpp | 54 +++++++++++++++++++++--- 10 files changed, 130 insertions(+), 50 deletions(-) diff --git a/include/xeus-python/xasync_runner.hpp b/include/xeus-python/xasync_runner.hpp index 7a4d619e..15034688 100644 --- a/include/xeus-python/xasync_runner.hpp +++ b/include/xeus-python/xasync_runner.hpp @@ -14,8 +14,11 @@ #include "xeus-python/xeus_python_config.hpp" #include "xeus-zmq/xshell_runner.hpp" +#include "pybind11/pybind11.h" +namespace py = pybind11; + namespace xpyt { @@ -23,7 +26,7 @@ namespace xpyt { public: - xasync_runner(); + xasync_runner(py::dict globals); xasync_runner(const xasync_runner&) = delete; xasync_runner& operator=(const xasync_runner&) = delete; @@ -37,7 +40,8 @@ namespace xpyt void on_message_doorbell_controller(); void run_impl() override; - + + py::dict m_global_dict; }; diff --git a/include/xeus-python/xdebugger.hpp b/include/xeus-python/xdebugger.hpp index a7268818..6f751711 100644 --- a/include/xeus-python/xdebugger.hpp +++ b/include/xeus-python/xdebugger.hpp @@ -40,7 +40,9 @@ namespace xpyt using base_type = xeus::xdebugger_base; - debugger(xeus::xcontext& context, + debugger( + py::dict globals, + xeus::xcontext& context, const xeus::xconfiguration& config, const std::string& user_name, const std::string& session_id, @@ -65,6 +67,9 @@ namespace xpyt xeus::xdebugger_info get_debugger_info() const override; std::string get_cell_temporary_file(const std::string& code) const override; + + py::dict m_global_dict; + std::unique_ptr p_debugpy_client; std::string m_debugpy_host; std::string m_debugpy_port; @@ -75,7 +80,8 @@ namespace xpyt }; XEUS_PYTHON_API - std::unique_ptr make_python_debugger(xeus::xcontext& context, + std::unique_ptr make_python_debugger(py::dict globals, + xeus::xcontext& context, const xeus::xconfiguration& config, const std::string& user_name, const std::string& session_id, diff --git a/include/xeus-python/xinterpreter.hpp b/include/xeus-python/xinterpreter.hpp index 6ffdae81..14f7d561 100644 --- a/include/xeus-python/xinterpreter.hpp +++ b/include/xeus-python/xinterpreter.hpp @@ -44,7 +44,9 @@ namespace xpyt // If redirect_display_enabled is true (default) then this interpreter will // overwrite sys.displayhook and send execution results using publish_execution_result. // Disable this if your interpreter uses custom display hook. - interpreter(bool redirect_output_enabled=true, bool redirect_display_enabled = true); + interpreter( + py::dict globals, + bool redirect_output_enabled=true, bool redirect_display_enabled = true); virtual ~interpreter(); protected: @@ -76,6 +78,7 @@ namespace xpyt void redirect_output(); + py::dict m_global_dict; py::object m_ipython_shell_app; py::object m_ipython_shell; py::object m_displayhook; @@ -92,7 +95,6 @@ namespace xpyt // If an application has already released the GIL by the time the interpreter // is started, m_release_gil_at_startup has to be set to false to prevent // releasing it again in configure_impl(). - // bool m_release_gil_at_startup = false; gil_scoped_release_ptr m_release_gil = nullptr; diff --git a/include/xeus-python/xinterpreter_raw.hpp b/include/xeus-python/xinterpreter_raw.hpp index 9760cba3..4b8143a6 100644 --- a/include/xeus-python/xinterpreter_raw.hpp +++ b/include/xeus-python/xinterpreter_raw.hpp @@ -42,7 +42,9 @@ namespace xpyt // If redirect_display_enabled is true (default) then this interpreter will // overwrite sys.displayhook and send execution results using publish_execution_result. // Disable this if your interpreter uses custom display hook. - raw_interpreter(bool redirect_output_enabled=true, bool redirect_display_enabled = true); + raw_interpreter( + py::dict globals, + bool redirect_output_enabled=true, bool redirect_display_enabled = true); virtual ~raw_interpreter(); protected: diff --git a/src/main.cpp b/src/main.cpp index 6d924512..af100944 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -124,17 +124,25 @@ int main(int argc, char* argv[]) std::unique_ptr context = xeus::make_zmq_context(); + + + + py::dict globals = py::globals(); + + + + // Instantiating the xeus xinterpreter bool raw_mode = xpyt::extract_option("-r", "--raw", argc, argv); using interpreter_ptr = std::unique_ptr; interpreter_ptr interpreter; if (raw_mode) { - interpreter = interpreter_ptr(new xpyt::raw_interpreter()); + interpreter = interpreter_ptr(new xpyt::raw_interpreter(globals)); } else { - interpreter = interpreter_ptr(new xpyt::interpreter()); + interpreter = interpreter_ptr(new xpyt::interpreter(globals)); } using history_manager_ptr = std::unique_ptr; @@ -158,21 +166,7 @@ int main(int argc, char* argv[]) - - // auto make_xserver = [&](xeus::xcontext& context, - // const xeus::xconfiguration& config, - // nl::json::error_handler_t eh) { - // return xeus::make_xserver_uv(context, config, eh, loop_ptr, std::move(py_hook)); - // }; - - - - - // create the runner by hand - - - - auto make_xserver = []( + auto make_xserver = [&globals]( xeus::xcontext& context, const xeus::xconfiguration& config, nl::json::error_handler_t eh) @@ -184,12 +178,30 @@ int main(int argc, char* argv[]) config, eh, std::make_unique(), - std::make_unique() + std::make_unique(globals) ); }; + auto make_the_debugger = [globals]( + xeus::xcontext& context, + const xeus::xconfiguration& config, + const std::string& user_name, + const std::string& session_id, + const nl::json& debugger_config) -> std::unique_ptr + { + return xpyt::make_python_debugger( + globals, + context, + config, + user_name, + session_id, + debugger_config); + }; + + + @@ -209,7 +221,7 @@ int main(int argc, char* argv[]) std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), - xpyt::make_python_debugger, + make_the_debugger, debugger_config); std::clog << @@ -231,7 +243,7 @@ int main(int argc, char* argv[]) make_xserver, std::move(hist), nullptr, - xpyt::make_python_debugger, + make_the_debugger, debugger_config); std::cout << "Getting config" << std::endl; diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 798a7c53..d79bb41e 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -19,8 +19,9 @@ namespace py = pybind11; namespace xpyt { - xasync_runner::xasync_runner() - : xeus::xshell_runner() + xasync_runner::xasync_runner(py::dict globals) + : xeus::xshell_runner(), + m_global_dict{globals} { std::cout<< "xasync_runner created" << std::endl; } @@ -92,9 +93,9 @@ namespace xpyt loop.run_forever() - )", py::globals()); + )", m_global_dict); - py::object run_func = py::globals()["run_main"]; + py::object run_func = m_global_dict["run_main"]; run_func(fd_shell_int, fd_controller_int, shell_callback, controller_callback); @@ -153,9 +154,9 @@ namespace xpyt loop.stop() - )", py::globals()); + )", m_global_dict); - py::object stop_func = py::globals()["stop_loop"]; + py::object stop_func = m_global_dict["stop_loop"]; stop_func(fd_shell_int, fd_controller_int); } diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index f6a6624b..b5d146f5 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -43,12 +43,14 @@ using namespace std::placeholders; namespace xpyt { - debugger::debugger(xeus::xcontext& context, + debugger::debugger(py::dict globals, + xeus::xcontext& context, const xeus::xconfiguration& config, const std::string& user_name, const std::string& session_id, const nl::json& debugger_config) : xdebugger_base(context) + , m_global_dict{globals} , p_debugpy_client(new xdebugpy_client(context, config, xeus::get_socket_linger(), @@ -146,7 +148,7 @@ namespace xpyt } py::gil_scoped_acquire acquire; - py::object variables = py::globals(); + py::object variables = m_global_dict; py::object repr_data = variables[py::str(var_repr_data)]; py::object repr_metadata = variables[py::str(var_repr_metadata)]; nl::json body = { @@ -290,7 +292,7 @@ namespace xpyt // Get debugpy version std::string expression = "debugpy.__version__"; - std::string version = (eval(py::str(expression))).cast(); + std::string version = (eval(py::str(expression)), m_global_dict).cast(); // Format the version to match [0-9]+(\s[0-9]+)* size_t pos = version.find_first_of("abrc"); @@ -363,13 +365,15 @@ namespace xpyt return get_cell_tmp_file(code); } - std::unique_ptr make_python_debugger(xeus::xcontext& context, + std::unique_ptr make_python_debugger( + py::dict globals, + xeus::xcontext& context, const xeus::xconfiguration& config, const std::string& user_name, const std::string& session_id, const nl::json& debugger_config) { - return std::unique_ptr(new debugger(context, + return std::unique_ptr(new debugger(globals,context, config, user_name, session_id, debugger_config)); } diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 4680fff5..293751da 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -44,8 +44,11 @@ using namespace pybind11::literals; namespace xpyt { - interpreter::interpreter(bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/) - : m_redirect_output_enabled{redirect_output_enabled}, m_redirect_display_enabled{redirect_display_enabled} + interpreter::interpreter( + py::dict globals, + bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/) + : m_global_dict{globals}, + m_redirect_output_enabled{redirect_output_enabled}, m_redirect_display_enabled{redirect_display_enabled} { xeus::register_interpreter(this); } @@ -184,7 +187,7 @@ namespace xpyt try { - + m_ipython_shell.attr("run_cell_async")(code, when_done_callback, "store_history"_a=config.store_history, "silent"_a=config.silent); } catch(std::runtime_error& e) diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index d9c7886c..0f81e75f 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -45,10 +45,14 @@ using namespace pybind11::literals; namespace xpyt { - raw_interpreter::raw_interpreter(bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/) - :m_redirect_display_enabled{ redirect_display_enabled } + raw_interpreter::raw_interpreter( + py::dict globals, + bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/) + + : m_global_dict{globals}, + m_redirect_display_enabled{ redirect_display_enabled } { - m_global_dict = py::globals(); + xeus::register_interpreter(this); if (redirect_output_enabled) { diff --git a/src/xpython_extension.cpp b/src/xpython_extension.cpp index c27618b0..861c6f90 100644 --- a/src/xpython_extension.cpp +++ b/src/xpython_extension.cpp @@ -35,6 +35,11 @@ #include "xeus-python/xdebugger.hpp" #include "xeus-python/xutils.hpp" +#include "xeus-python/xasync_runner.hpp" +#include "xeus-zmq/xcontrol_default_runner.hpp" +#include "xeus-zmq/xserver_zmq_split.hpp" + + namespace py = pybind11; @@ -70,18 +75,55 @@ void launch(const py::list args_list) std::unique_ptr context = xeus::make_zmq_context(); + + py::dict globals = py::globals(); + // Instantiating the xeus xinterpreter using interpreter_ptr = std::unique_ptr; interpreter_ptr interpreter; if (raw_mode) { - interpreter = interpreter_ptr(new xpyt::raw_interpreter()); + interpreter = interpreter_ptr(new xpyt::raw_interpreter(globals)); } else { - interpreter = interpreter_ptr(new xpyt::interpreter()); + interpreter = interpreter_ptr(new xpyt::interpreter(globals)); } + auto make_xserver = [&globals]( + xeus::xcontext& context, + const xeus::xconfiguration& config, + nl::json::error_handler_t eh) + { + std::cout << "Creating xserver_uv" << std::endl; + return xeus::make_xserver_shell + ( + context, + config, + eh, + std::make_unique(), + std::make_unique(globals) + ); + }; + auto make_the_debugger = [&globals]( + xeus::xcontext& context, + const xeus::xconfiguration& config, + const std::string& user_name, + const std::string& session_id, + const nl::json& debugger_config) -> std::unique_ptr + { + return xpyt::make_python_debugger( + globals, + context, + config, + user_name, + session_id, + debugger_config); + }; + + + + using history_manager_ptr = std::unique_ptr; history_manager_ptr hist = xeus::make_in_memory_history_manager(); @@ -100,11 +142,11 @@ void launch(const py::list args_list) xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_shell_main, + make_xserver, std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), - xpyt::make_python_debugger); + make_the_debugger); std::clog << "Starting xeus-python kernel...\n\n" @@ -119,10 +161,10 @@ void launch(const py::list args_list) xeus::xkernel kernel(xeus::get_user_name(), std::move(context), std::move(interpreter), - xeus::make_xserver_shell_main, + make_xserver, std::move(hist), nullptr, - xpyt::make_python_debugger); + make_the_debugger); const auto& config = kernel.get_config(); std::clog << From cf4bbfa090a479049a841c1528b485e729925482 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 14:06:17 +0100 Subject: [PATCH 067/112] fixes --- src/main.cpp | 2 +- src/xdebugger.cpp | 5 ++++- src/xinterpreter.cpp | 17 ++++++++++++++++- src/xutils.cpp | 5 +++-- test/test_debugger.cpp | 38 +++++++++++++++++++------------------- 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index af100944..65df7a84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -221,7 +221,7 @@ int main(int argc, char* argv[]) std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), - make_the_debugger, + make_the_debugger, debugger_config); std::clog << diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index b5d146f5..e2cb5f1f 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -24,6 +24,7 @@ #include "pybind11/pybind11.h" #include "pybind11/stl.h" +#include "pybind11/embed.h" #include "xeus/xinterpreter.hpp" #include "xeus/xeus_context.hpp" @@ -270,7 +271,9 @@ namespace xpyt code += "debugpy.listen((\'" + m_debugpy_host + "\'," + m_debugpy_port + "))"; nl::json json_code; json_code["code"] = code; + std::cout<<"sending code to import and start debugpy: "<(); if(status != "ok") { @@ -292,7 +295,7 @@ namespace xpyt // Get debugpy version std::string expression = "debugpy.__version__"; - std::string version = (eval(py::str(expression)), m_global_dict).cast(); + std::string version = eval(py::str(expression), m_global_dict).cast(); // Format the version to match [0-9]+(\s[0-9]+)* size_t pos = version.find_first_of("abrc"); diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 293751da..820810b6 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -22,6 +22,7 @@ #include "xeus/xhelper.hpp" #include "pybind11/functional.h" +#include "pybind11/embed.h" #include "pybind11_json/pybind11_json.hpp" @@ -379,7 +380,19 @@ namespace xpyt try { - exec(py::str(code)); + std::cout<<"Executing internal_request_impl code: "<()<() << ": " << py::str(item.second).cast() << std::endl; + } + return xeus::create_successful_reply(); } catch (py::error_already_set& e) @@ -391,6 +404,8 @@ namespace xpyt xerror error = extract_error(pyerror); + std::cout<<"Exception occurred during internal_request_impl: "<()) { shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); throw std::runtime_error("Could not initialize debugger, exiting"); } m_client.send_on_control("debug_request", make_attach_request(3)); @@ -1152,7 +1152,7 @@ void start_kernel() dump_connection_file(); std::string cmd = "xpython -f " + KERNEL_JSON + "&"; int ret2 = std::system(cmd.c_str()); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); } TEST_SUITE("debugger") @@ -1168,7 +1168,7 @@ TEST_SUITE("debugger") bool res = deb.test_init(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1184,7 +1184,7 @@ TEST_SUITE("debugger") deb.start(); bool res = deb.test_disconnect(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1201,7 +1201,7 @@ TEST_SUITE("debugger") bool res = deb.test_attach(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1216,10 +1216,10 @@ TEST_SUITE("debugger") debugger_client deb(*context_ptr, KERNEL_JSON, "debugger_multi_session.log"); deb.start(); bool res1 = deb.test_disconnect(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); bool res2 = deb.test_disconnect(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res1); CHECK(res2); t.notify_done(); @@ -1237,7 +1237,7 @@ TEST_SUITE("debugger") bool res = deb.test_external_set_breakpoints(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1256,7 +1256,7 @@ TEST_SUITE("debugger") bool res = deb.test_external_next_continue(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1273,7 +1273,7 @@ TEST_SUITE("debugger") bool res = deb.test_set_breakpoints(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1307,7 +1307,7 @@ TEST_SUITE("debugger") bool res = deb.test_source(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1326,7 +1326,7 @@ TEST_SUITE("debugger") bool res = deb.test_next_continue(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1346,7 +1346,7 @@ TEST_SUITE("debugger") bool res = deb.test_step_in(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1364,7 +1364,7 @@ TEST_SUITE("debugger") bool res = deb.test_stack_trace(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1381,7 +1381,7 @@ TEST_SUITE("debugger") bool res = deb.test_debug_info(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1398,7 +1398,7 @@ TEST_SUITE("debugger") bool res = deb.test_inspect_variables(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1416,7 +1416,7 @@ TEST_SUITE("debugger") deb.start(); bool res = deb.test_rich_inspect_variables(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1434,7 +1434,7 @@ TEST_SUITE("debugger") bool res = deb.test_variables(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } @@ -1451,7 +1451,7 @@ TEST_SUITE("debugger") bool res = deb.test_copy_to_globals(); deb.disconnect_debugger(); deb.shutdown(); - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(4s); CHECK(res); t.notify_done(); } From 1315e048b9bda160c0c78bd8a96b444d4b845fba Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 14:37:39 +0100 Subject: [PATCH 068/112] fixes --- src/xutils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/xutils.cpp b/src/xutils.cpp index c311c132..ad4282af 100644 --- a/src/xutils.cpp +++ b/src/xutils.cpp @@ -58,13 +58,13 @@ namespace xpyt void exec(const py::object& code, const py::object& scope) { - // py::exec("exec(_code_, _scope_, _scope_)", py::globals(), py::dict(py::arg("_code_") = code, py::arg("_scope_") = scope)); - py::exec(code, scope, scope); + py::exec("exec(_code_, _scope_, _scope_)", py::globals(), py::dict(py::arg("_code_") = code, py::arg("_scope_") = scope)); + // py::exec(code, scope, scope); } py::object eval(const py::object& code, const py::object& scope) { - return py::eval(code, scope, scope); + return py::eval(code, scope); } bool extract_option(std::string short_opt, std::string long_opt, int argc, char* argv[]) From d1afdb4dfe850218d3b0f35cc4189bd4e0d71a54 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 14:46:10 +0100 Subject: [PATCH 069/112] fixes --- src/xinterpreter_wasm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xinterpreter_wasm.cpp b/src/xinterpreter_wasm.cpp index 38c3e205..333a56e1 100644 --- a/src/xinterpreter_wasm.cpp +++ b/src/xinterpreter_wasm.cpp @@ -22,7 +22,7 @@ namespace xpyt { wasm_interpreter::wasm_interpreter() - : interpreter(true, true) + : interpreter(py::globals(), true, true) { m_release_gil_at_startup = false; } From 5d9972fc2bd521b6cd19fb7b1d60919e3dff179b Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 14:47:27 +0100 Subject: [PATCH 070/112] fixes --- src/xinterpreter_raw.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index 0f81e75f..b5a2daf9 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -49,8 +49,8 @@ namespace xpyt py::dict globals, bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/) - : m_global_dict{globals}, - m_redirect_display_enabled{ redirect_display_enabled } + : m_redirect_display_enabled{ redirect_display_enabled }, + m_global_dict{globals} { xeus::register_interpreter(this); From eb7672607258a7711b69dbd05d78628a9fdb2697 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 14:59:43 +0100 Subject: [PATCH 071/112] fixes --- .github/workflows/main.yml | 2 +- src/xasync_runner.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fab5b9cb..4dd2aea1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: environment-file: environment-dev.yml - name: Install xeus-python-shell from GitHub - run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv + run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv --ignore-dependencies - name: Make build directory diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index d79bb41e..cbe1034c 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -19,6 +19,7 @@ namespace py = pybind11; namespace xpyt { + xasync_runner::xasync_runner(py::dict globals) : xeus::xshell_runner(), m_global_dict{globals} From 5f00b207a0f681472e4731439e1697a4b55f755f Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 15:02:14 +0100 Subject: [PATCH 072/112] fixes --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4dd2aea1..b56bc356 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: environment-file: environment-dev.yml - name: Install xeus-python-shell from GitHub - run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv --ignore-dependencies + run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv - name: Make build directory From 091a8bf161236436095b4301908e43ffa4208b0b Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 15:12:43 +0100 Subject: [PATCH 073/112] fixes --- include/xeus-python/xasync_runner.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/xeus-python/xasync_runner.hpp b/include/xeus-python/xasync_runner.hpp index 15034688..5971a0d2 100644 --- a/include/xeus-python/xasync_runner.hpp +++ b/include/xeus-python/xasync_runner.hpp @@ -22,7 +22,7 @@ namespace py = pybind11; namespace xpyt { - class XEUS_PYTHON_API xasync_runner final : public xeus::xshell_runner + class XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT xasync_runner final : public xeus::xshell_runner { public: From 4214603cd94001e2d8565a023a52a0b308d4b2f8 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 15:35:44 +0100 Subject: [PATCH 074/112] fixes --- .github/workflows/main.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b56bc356..5dcba786 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,7 +51,20 @@ jobs: run: | CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXPYT_BUILD_STATIC=OFF" echo "CMAKE_EXTRA_ARGS=$CMAKE_EXTRA_ARGS" >> $GITHUB_ENV - + + - name: show all installed libraries + run: | + # we want to show everything in $CONDA_PREFIX/lib + ls -la $CONDA_PREFIX/lib + + # we want to find if there is any libpython installed + find $CONDA_PREFIX/lib -name "libpython*" + + # find globally + find /usr/lib -name "libpython*" + find /usr/local/lib -name "libpython*" + find / lib -name "libpython*" + - name: Configure cmake run: | cmake .. \ From 264f7a56a5488e9374b7609dd15055f595d2d6f9 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 15:38:07 +0100 Subject: [PATCH 075/112] fixes --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5dcba786..73bbcf0e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,12 +58,12 @@ jobs: ls -la $CONDA_PREFIX/lib # we want to find if there is any libpython installed - find $CONDA_PREFIX/lib -name "libpython*" + find $CONDA_PREFIX/lib -name "libxeus*" # find globally - find /usr/lib -name "libpython*" - find /usr/local/lib -name "libpython*" - find / lib -name "libpython*" + find /usr/lib -name "libxeus*" + find /usr/local/lib -name "libxeus*" + find / lib -name "libxeus*" - name: Configure cmake run: | From ffb3b0f6e15aa78ae14f9172aba0b3134ca4e7f2 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 16:04:09 +0100 Subject: [PATCH 076/112] more --- CMakeLists.txt | 3 +- include/xeus-python/xaserver.hpp | 22 ++++++++++ src/main.cpp | 26 ++---------- src/xaserver.cpp | 41 +++++++++++++++++++ src/xasync_runner.cpp | 4 +- .../xeus-python => src}/xasync_runner.hpp | 0 6 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 include/xeus-python/xaserver.hpp create mode 100644 src/xaserver.cpp rename {include/xeus-python => src}/xasync_runner.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a197a96f..661f93c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,7 @@ set(XEUS_PYTHON_SRC src/xtraceback.cpp src/xutils.cpp src/xasync_runner.cpp + src/xaserver.cpp ) set(XEUS_PYTHON_HEADERS @@ -192,7 +193,7 @@ set(XEUS_PYTHON_HEADERS include/xeus-python/xinterpreter_raw.hpp include/xeus-python/xtraceback.hpp include/xeus-python/xutils.hpp - include/xeus-python/xasync_runner.hpp + include/xeus-python/xaserver.hpp ) set(XPYTHON_SRC diff --git a/include/xeus-python/xaserver.hpp b/include/xeus-python/xaserver.hpp new file mode 100644 index 00000000..5521f3c0 --- /dev/null +++ b/include/xeus-python/xaserver.hpp @@ -0,0 +1,22 @@ +/*************************************************************************** +* Copyright (c) 2024, Isabel Paredes * +* Copyright (c) 2024, QuantStack * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#include "xeus_python_config.hpp" +#include "xeus/xkernel.hpp" +#include "pybind11/pybind11.h" + +namespace py = pybind11; +namespace nl = nlohmann; + +namespace xpyt +{ + + XEUS_PYTHON_API xeus::xkernel::server_builder make_xaserver_factory(py::dict globals); + +} // namespace xeus diff --git a/src/main.cpp b/src/main.cpp index 65df7a84..b7fc56cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,9 +43,7 @@ #include "xeus-python/xutils.hpp" -#include "xeus-python/xasync_runner.hpp" -#include "xeus-zmq/xcontrol_default_runner.hpp" -#include "xeus-zmq/xserver_zmq_split.hpp" +#include "xeus-python/xaserver.hpp" namespace py = pybind11; @@ -166,24 +164,6 @@ int main(int argc, char* argv[]) - auto make_xserver = [&globals]( - xeus::xcontext& context, - const xeus::xconfiguration& config, - nl::json::error_handler_t eh) - { - std::cout << "Creating xserver_uv" << std::endl; - return xeus::make_xserver_shell - ( - context, - config, - eh, - std::make_unique(), - std::make_unique(globals) - ); - }; - - - auto make_the_debugger = [globals]( xeus::xcontext& context, const xeus::xconfiguration& config, @@ -217,7 +197,7 @@ int main(int argc, char* argv[]) xeus::get_user_name(), std::move(context), std::move(interpreter), - make_xserver, + xpyt::make_xaserver_factory(globals), std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), @@ -240,7 +220,7 @@ int main(int argc, char* argv[]) xeus::xkernel kernel(xeus::get_user_name(), std::move(context), std::move(interpreter), - make_xserver, + xpyt::make_xaserver_factory(globals), std::move(hist), nullptr, make_the_debugger, diff --git a/src/xaserver.cpp b/src/xaserver.cpp new file mode 100644 index 00000000..804af8fb --- /dev/null +++ b/src/xaserver.cpp @@ -0,0 +1,41 @@ + +#include "xeus-python/xaserver.hpp" +#include "xasync_runner.hpp" +#include "xeus-zmq/xcontrol_default_runner.hpp" +#include "xeus-zmq/xserver_zmq_split.hpp" + +#include "xeus/xkernel.hpp" +#include "xeus/xserver.hpp" +#include "xeus/xeus_context.hpp" +#include "xeus/xkernel_configuration.hpp" + +#include "nlohmann/json.hpp" + + +namespace nl = nlohmann; + +namespace xpyt +{ + + + + xeus::xkernel::server_builder make_xaserver_factory(py::dict globals) + { + return [globals]( + xeus::xcontext& context, + const xeus::xconfiguration& config, + nl::json::error_handler_t eh) + { + return xeus::make_xserver_shell + ( + context, + config, + eh, + std::make_unique(), + std::make_unique(globals) + ); + }; + } + + +} // namespace xeus diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index cbe1034c..8fd5e0a8 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -10,7 +10,7 @@ #include #include -#include "xeus-python/xasync_runner.hpp" +#include "xasync_runner.hpp" #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -19,7 +19,7 @@ namespace py = pybind11; namespace xpyt { - + xasync_runner::xasync_runner(py::dict globals) : xeus::xshell_runner(), m_global_dict{globals} diff --git a/include/xeus-python/xasync_runner.hpp b/src/xasync_runner.hpp similarity index 100% rename from include/xeus-python/xasync_runner.hpp rename to src/xasync_runner.hpp From 13778eec9166b4eb314b789ff4c0e1d3727eef18 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 16:06:36 +0100 Subject: [PATCH 077/112] more --- src/xasync_runner.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xasync_runner.hpp b/src/xasync_runner.hpp index 5971a0d2..12dbd771 100644 --- a/src/xasync_runner.hpp +++ b/src/xasync_runner.hpp @@ -22,7 +22,7 @@ namespace py = pybind11; namespace xpyt { - class XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT xasync_runner final : public xeus::xshell_runner + class xasync_runner final : public xeus::xshell_runner { public: From b9a9826566197ca936c1b05551fd8072d4e3e6e2 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 16:09:36 +0100 Subject: [PATCH 078/112] more --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 73bbcf0e..faae8b25 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,7 +63,7 @@ jobs: # find globally find /usr/lib -name "libxeus*" find /usr/local/lib -name "libxeus*" - find / lib -name "libxeus*" + find / -name "libxeus*" - name: Configure cmake run: | From ae16a96eaebf00117d9dc005752e72c4c7fb2fc5 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 16:11:00 +0100 Subject: [PATCH 079/112] more --- src/xpython_extension.cpp | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/xpython_extension.cpp b/src/xpython_extension.cpp index 861c6f90..ec842f5e 100644 --- a/src/xpython_extension.cpp +++ b/src/xpython_extension.cpp @@ -35,10 +35,7 @@ #include "xeus-python/xdebugger.hpp" #include "xeus-python/xutils.hpp" -#include "xeus-python/xasync_runner.hpp" -#include "xeus-zmq/xcontrol_default_runner.hpp" -#include "xeus-zmq/xserver_zmq_split.hpp" - +#include "xeus-python/xaserver.hpp" namespace py = pybind11; @@ -90,21 +87,7 @@ void launch(const py::list args_list) interpreter = interpreter_ptr(new xpyt::interpreter(globals)); } - auto make_xserver = [&globals]( - xeus::xcontext& context, - const xeus::xconfiguration& config, - nl::json::error_handler_t eh) - { - std::cout << "Creating xserver_uv" << std::endl; - return xeus::make_xserver_shell - ( - context, - config, - eh, - std::make_unique(), - std::make_unique(globals) - ); - }; + auto make_the_debugger = [&globals]( xeus::xcontext& context, const xeus::xconfiguration& config, @@ -142,7 +125,7 @@ void launch(const py::list args_list) xeus::get_user_name(), std::move(context), std::move(interpreter), - make_xserver, + xpyt::make_xaserver_factory(globals), std::move(hist), xeus::make_console_logger(xeus::xlogger::msg_type, xeus::make_file_logger(xeus::xlogger::content, "xeus.log")), @@ -161,7 +144,7 @@ void launch(const py::list args_list) xeus::xkernel kernel(xeus::get_user_name(), std::move(context), std::move(interpreter), - make_xserver, + xpyt::make_xaserver_factory(globals), std::move(hist), nullptr, make_the_debugger); From 4f667a5dcde36eeccd950159acb53e3c27d6a009 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 16:16:12 +0100 Subject: [PATCH 080/112] more --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index faae8b25..57b0003e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,7 +63,7 @@ jobs: # find globally find /usr/lib -name "libxeus*" find /usr/local/lib -name "libxeus*" - find / -name "libxeus*" + - name: Configure cmake run: | From 2bd30a841deb2c1429c502d14a116b59900a6652 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 16:30:35 +0100 Subject: [PATCH 081/112] more --- .github/workflows/main.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57b0003e..41ade3a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,18 +52,6 @@ jobs: CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXPYT_BUILD_STATIC=OFF" echo "CMAKE_EXTRA_ARGS=$CMAKE_EXTRA_ARGS" >> $GITHUB_ENV - - name: show all installed libraries - run: | - # we want to show everything in $CONDA_PREFIX/lib - ls -la $CONDA_PREFIX/lib - - # we want to find if there is any libpython installed - find $CONDA_PREFIX/lib -name "libxeus*" - - # find globally - find /usr/lib -name "libxeus*" - find /usr/local/lib -name "libxeus*" - - name: Configure cmake run: | From acf7c65daeae2b4f73cdf710fc53ab1979c31da3 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 19:02:02 +0100 Subject: [PATCH 082/112] more --- .github/workflows/main.yml | 13 ++++++++++++- CMakeLists.txt | 7 +++++++ src/main.cpp | 1 - 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 41ade3a8..fd6b03a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,8 +66,19 @@ jobs: ${{ env.CMAKE_EXTRA_ARGS }} working-directory: build + - name: Build + run: cmake --build . --target xeus-python --verbose -j ${{ runner.os == 'macOS' && 3 || 4 }} + working-directory: build + + - name: Inspect build lib + run: nm build/libxeus-python.so | grep raw_interpreter + + - name: Build all targets + run: cmake --build . --verbose -j ${{ runner.os == 'macOS' && 3 || 4 }} + working-directory: build + - name: Install - run: make -j ${{ runner.os == 'macOS' && 3 || 4 }} install + run: cmake --install . working-directory: build - name: Print version diff --git a/CMakeLists.txt b/CMakeLists.txt index 661f93c3..ebb7dbd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -385,6 +385,13 @@ if (XPYT_BUILD_XPYTHON_EXECUTABLE) xpyt_set_common_options(xpython) xpyt_set_kernel_options(xpython) xpyt_target_link_libraries(xpython) + + get_target_property(_libs xpython LINK_LIBRARIES) + message(STATUS "xpython LINK_LIBRARIES = ${_libs}") + + message(STATUS "xeus-python file = $") + + endif() # xpython_extension diff --git a/src/main.cpp b/src/main.cpp index b7fc56cf..577d8f09 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -188,7 +188,6 @@ int main(int argc, char* argv[]) - if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); From 0b69b19bc8854aae106af8e26ca7224dfb35f619 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 19:08:12 +0100 Subject: [PATCH 083/112] more --- include/xeus-python/xaserver.hpp | 2 +- include/xeus-python/xinterpreter.hpp | 2 +- include/xeus-python/xinterpreter_raw.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/xeus-python/xaserver.hpp b/include/xeus-python/xaserver.hpp index 5521f3c0..0382b39c 100644 --- a/include/xeus-python/xaserver.hpp +++ b/include/xeus-python/xaserver.hpp @@ -17,6 +17,6 @@ namespace nl = nlohmann; namespace xpyt { - XEUS_PYTHON_API xeus::xkernel::server_builder make_xaserver_factory(py::dict globals); + XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT xeus::xkernel::server_builder make_xaserver_factory(py::dict globals); } // namespace xeus diff --git a/include/xeus-python/xinterpreter.hpp b/include/xeus-python/xinterpreter.hpp index 14f7d561..378c3b29 100644 --- a/include/xeus-python/xinterpreter.hpp +++ b/include/xeus-python/xinterpreter.hpp @@ -32,7 +32,7 @@ namespace nl = nlohmann; namespace xpyt { - class XEUS_PYTHON_API interpreter : public xeus::xinterpreter + class XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT interpreter : public xeus::xinterpreter { public: diff --git a/include/xeus-python/xinterpreter_raw.hpp b/include/xeus-python/xinterpreter_raw.hpp index 4b8143a6..38cc9840 100644 --- a/include/xeus-python/xinterpreter_raw.hpp +++ b/include/xeus-python/xinterpreter_raw.hpp @@ -30,7 +30,7 @@ namespace nl = nlohmann; namespace xpyt { - class XEUS_PYTHON_API raw_interpreter : public xeus::xinterpreter + class XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT raw_interpreter : public xeus::xinterpreter { public: From 51c49671df3ac0d56208058390686fa57a9e1c02 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 19:11:24 +0100 Subject: [PATCH 084/112] more --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fd6b03a7..7ca488f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,12 +66,12 @@ jobs: ${{ env.CMAKE_EXTRA_ARGS }} working-directory: build - - name: Build - run: cmake --build . --target xeus-python --verbose -j ${{ runner.os == 'macOS' && 3 || 4 }} - working-directory: build + # - name: Build + # run: cmake --build . --target xeus-python --verbose -j ${{ runner.os == 'macOS' && 3 || 4 }} + # working-directory: build - - name: Inspect build lib - run: nm build/libxeus-python.so | grep raw_interpreter + # - name: Inspect build lib + # run: nm build/libxeus-python.so | grep raw_interpreter - name: Build all targets run: cmake --build . --verbose -j ${{ runner.os == 'macOS' && 3 || 4 }} From e7f655059589e28b4a1d67f4a573bd6175419205 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 19:18:28 +0100 Subject: [PATCH 085/112] more --- include/xeus-python/xdebugger.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/xeus-python/xdebugger.hpp b/include/xeus-python/xdebugger.hpp index 6f751711..055c1358 100644 --- a/include/xeus-python/xdebugger.hpp +++ b/include/xeus-python/xdebugger.hpp @@ -79,7 +79,7 @@ namespace xpyt bool m_copy_to_globals_available; }; - XEUS_PYTHON_API + XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT std::unique_ptr make_python_debugger(py::dict globals, xeus::xcontext& context, const xeus::xconfiguration& config, From d99c17b095ee524c94c2823d6371b486a4820cc4 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 20:26:48 +0100 Subject: [PATCH 086/112] more --- src/xasync_runner.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 8fd5e0a8..ae25124b 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -58,18 +58,18 @@ namespace xpyt import sys is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") - + print("is_win:", is_win) import asyncio if is_win: async def loop_shell(fd_shell, shell_callback): while True: - await asyncio.sleep(0.01) + await asyncio.sleep() shell_callback() controller_callback() async def loop_controller(fd_controller, controller_callback): while True: - await asyncio.sleep(0.01) + await asyncio.sleep() controller_callback() shell_callback() @@ -97,6 +97,7 @@ namespace xpyt )", m_global_dict); py::object run_func = m_global_dict["run_main"]; + std::cout << "Starting async loop "<< std::endl; run_func(fd_shell_int, fd_controller_int, shell_callback, controller_callback); From ef0820d3de15578761d510d80282966c8f6c2737 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 20:33:39 +0100 Subject: [PATCH 087/112] more --- src/xasync_runner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index ae25124b..65335654 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -57,8 +57,9 @@ namespace xpyt py::exec(R"( import sys + import os is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") - print("is_win:", is_win) + os.write(1, b"is_win: " + str(is_win).encode() + b"\n") import asyncio if is_win: From 97edd8d3f14ad198c37371de1fae61c4f8b333c4 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 20:39:36 +0100 Subject: [PATCH 088/112] more --- src/xasync_runner.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 65335654..1443517c 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -57,9 +57,11 @@ namespace xpyt py::exec(R"( import sys - import os is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") - os.write(1, b"is_win: " + str(is_win).encode() + b"\n") + print("is_win:", is_win) + + sys.stdout.write(f"is win: {is_win}\n") + sys.stdout.flush() import asyncio if is_win: From abcdf81c87007e0ff5a3ca4235ac8067515d12ed Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 20:50:39 +0100 Subject: [PATCH 089/112] more info --- src/xasync_runner.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 1443517c..01729cd2 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -54,7 +54,14 @@ namespace xpyt // ensure gil py::gil_scoped_acquire acquire; - py::exec(R"( + + auto func = py::cpp_function([]( + std::string msg + ) { + std::cout << "Received message in Python: " << msg << std::endl; + }); + + exec(R"( import sys is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") @@ -65,29 +72,28 @@ namespace xpyt import asyncio if is_win: - async def loop_shell(fd_shell, shell_callback): + async def loop_shell(fd_shell, shell_callback, func): while True: + func("polling for shell message") await asyncio.sleep() shell_callback() - controller_callback() - async def loop_controller(fd_controller, controller_callback): + async def loop_controller(fd_controller, controller_callback, func): while True: + func("polling for controller message") await asyncio.sleep() - controller_callback() - shell_callback() - - - def run_main(fd_shell, fd_controller, shell_callback, controller_callback): + controller_callback() + def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): + func("Starting async loop on Windows") # here we create / ensure we have an event loop loop = asyncio.get_event_loop() - task_shell = loop.create_task(loop_shell(fd_shell, shell_callback)) - task_controller = loop.create_task(loop_controller(fd_controller, controller_callback)) - + task_shell = loop.create_task(loop_shell(fd_shell, shell_callback, func)) + task_controller = loop.create_task(loop_controller(fd_controller, controller_callback, func)) + loop.run_forever() else: - def run_main(fd_shell, fd_controller, shell_callback, controller_callback): + def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): # here we create / ensure we have an event loop loop = asyncio.get_event_loop() @@ -101,7 +107,7 @@ namespace xpyt py::object run_func = m_global_dict["run_main"]; std::cout << "Starting async loop "<< std::endl; - run_func(fd_shell_int, fd_controller_int, shell_callback, controller_callback); + run_func(fd_shell_int, fd_controller_int, shell_callback, controller_callback, func); } From 50bbcfcafb27eaf1158914c9978e91ff7c89a0fc Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 21:14:27 +0100 Subject: [PATCH 090/112] more info --- src/xasync_runner.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 01729cd2..4124b517 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -30,14 +30,14 @@ namespace xpyt void xasync_runner::run_impl() { std::cout << "get descriptors "<< std::endl; - #ifndef _WIN32 + //#ifndef _WIN32 int fd_shell_int = static_cast(this->get_shell_fd()); int fd_controller_int = static_cast(this-> get_shell_controller_fd()); - #else - // just use placeholders on Windows - int fd_shell_int = 0; - int fd_controller_int = 0; - #endif + // #else + // // just use placeholders on Windows + // int fd_shell_int = 0; + // int fd_controller_int = 0; + // #endif std::cout << "Got descriptors: " << fd_shell_int << ", " << fd_controller_int << std::endl; From ec209c649ceda0d05c05926f8304f2068444885e Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 21:15:33 +0100 Subject: [PATCH 091/112] even more --- src/xasync_runner.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 4124b517..f450cf65 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -74,14 +74,16 @@ namespace xpyt async def loop_shell(fd_shell, shell_callback, func): while True: - func("polling for shell message") - await asyncio.sleep() - shell_callback() + await asyncio.sleep() + func("polling for shell message") + shell_callback() + func("done polling for shell message") async def loop_controller(fd_controller, controller_callback, func): while True: - func("polling for controller message") - await asyncio.sleep() - controller_callback() + await asyncio.sleep() + func("polling for controller message") + controller_callback() + func("done polling for controller message") def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): func("Starting async loop on Windows") From a234d29f58d3f347a3b41509f97c8ab67d39ae4f Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 21:28:18 +0100 Subject: [PATCH 092/112] even more --- src/xasync_runner.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index f450cf65..e5ef0e4f 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -74,16 +74,16 @@ namespace xpyt async def loop_shell(fd_shell, shell_callback, func): while True: - await asyncio.sleep() - func("polling for shell message") - shell_callback() - func("done polling for shell message") + await asyncio.sleep() + func("polling for shell message") + shell_callback() + func("done polling for shell message") async def loop_controller(fd_controller, controller_callback, func): while True: - await asyncio.sleep() - func("polling for controller message") - controller_callback() - func("done polling for controller message") + await asyncio.sleep() + func("polling for controller message") + controller_callback() + func("done polling for controller message") def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): func("Starting async loop on Windows") From fc2e031b8fd53737bf9c6f895639e1fa36022b3b Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Fri, 16 Jan 2026 22:09:36 +0100 Subject: [PATCH 093/112] even more --- src/xasync_runner.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index e5ef0e4f..cee7105f 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -88,6 +88,10 @@ namespace xpyt def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): func("Starting async loop on Windows") # here we create / ensure we have an event loop + try: + loop = asyncio.get_event_loop() + except Exception as e: + func(f"Exception getting event loop: {e}") loop = asyncio.get_event_loop() task_shell = loop.create_task(loop_shell(fd_shell, shell_callback, func)) From 550fffc724eaef036d4558aa51ae46f00293c7fe Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Sat, 17 Jan 2026 14:06:25 +0100 Subject: [PATCH 094/112] no more specta --- src/xasync_runner.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index cee7105f..2b8d40f2 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -85,7 +85,7 @@ namespace xpyt controller_callback() func("done polling for controller message") - def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): + def run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func): func("Starting async loop on Windows") # here we create / ensure we have an event loop try: @@ -94,12 +94,16 @@ namespace xpyt func(f"Exception getting event loop: {e}") loop = asyncio.get_event_loop() + func("Creating tasks for shell and controller") task_shell = loop.create_task(loop_shell(fd_shell, shell_callback, func)) + + func("Creating task for controller") task_controller = loop.create_task(loop_controller(fd_controller, controller_callback, func)) + func("Running event loop forever") loop.run_forever() else: - def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): + def run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func): # here we create / ensure we have an event loop loop = asyncio.get_event_loop() @@ -108,6 +112,12 @@ namespace xpyt loop.add_reader(fd_controller, controller_callback) loop.run_forever() + + def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): + try: + run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func) + except Exception as e: + func(f"Exception in run_main: {e}" )", m_global_dict); From c6d6595d32dcc5a104395db09a7380291eae5c22 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Sat, 17 Jan 2026 14:16:37 +0100 Subject: [PATCH 095/112] no more specta --- src/xasync_runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 2b8d40f2..37c2dcc3 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -117,7 +117,7 @@ namespace xpyt try: run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func) except Exception as e: - func(f"Exception in run_main: {e}" + func(f"Exception in run_main: {e}") )", m_global_dict); From 7b7906879ba2304ba7635a19ab0651af6f195445 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Sat, 17 Jan 2026 14:27:28 +0100 Subject: [PATCH 096/112] no more specta --- src/xasync_runner.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 37c2dcc3..62ac4e3a 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -101,7 +101,12 @@ namespace xpyt task_controller = loop.create_task(loop_controller(fd_controller, controller_callback, func)) func("Running event loop forever") - loop.run_forever() + try: + loop.run_forever() + except Exception as e: + func(f"Exception in event loop: {e}") + finally: + func("Event loop has stopped") else: def run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func): From 210127fb534c94cf9039981ed05a18ff18cd72a0 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Sat, 17 Jan 2026 14:28:01 +0100 Subject: [PATCH 097/112] no more specta --- src/xasync_runner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 62ac4e3a..b2867181 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -73,12 +73,14 @@ namespace xpyt if is_win: async def loop_shell(fd_shell, shell_callback, func): + func("Starting shell loop on Windows") while True: await asyncio.sleep() func("polling for shell message") shell_callback() func("done polling for shell message") async def loop_controller(fd_controller, controller_callback, func): + func("Starting controller loop on Windows") while True: await asyncio.sleep() func("polling for controller message") From 03076830f863abf66f94a22c796de5e5fb06ecc4 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Sat, 17 Jan 2026 15:34:40 +0100 Subject: [PATCH 098/112] no more specta --- src/xasync_runner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index b2867181..e7e3686b 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -75,14 +75,14 @@ namespace xpyt async def loop_shell(fd_shell, shell_callback, func): func("Starting shell loop on Windows") while True: - await asyncio.sleep() + await asyncio.sleep(0) func("polling for shell message") shell_callback() func("done polling for shell message") async def loop_controller(fd_controller, controller_callback, func): func("Starting controller loop on Windows") while True: - await asyncio.sleep() + await asyncio.sleep(0) func("polling for controller message") controller_callback() func("done polling for controller message") From 03baf670552f046a83bc3ea3865cb5cfb9f27ef6 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Sat, 17 Jan 2026 15:36:52 +0100 Subject: [PATCH 099/112] no more specta --- src/xasync_runner.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index e7e3686b..448a75bd 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -73,19 +73,26 @@ namespace xpyt if is_win: async def loop_shell(fd_shell, shell_callback, func): - func("Starting shell loop on Windows") - while True: - await asyncio.sleep(0) - func("polling for shell message") - shell_callback() - func("done polling for shell message") + try: + func("Starting shell loop on Windows") + while True: + await asyncio.sleep(0) + func("polling for shell message") + shell_callback() + func("done polling for shell message") + except Exception as e: + func(f"Exception in loop_shell: {e}") async def loop_controller(fd_controller, controller_callback, func): - func("Starting controller loop on Windows") - while True: - await asyncio.sleep(0) - func("polling for controller message") - controller_callback() - func("done polling for controller message") + try: + func("Starting controller loop on Windows") + while True: + await asyncio.sleep(0) + func("polling for controller message") + controller_callback() + func("done polling for controller message") + except Exception as e: + func(f"Exception in loop_controller: {e}") + def run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func): func("Starting async loop on Windows") From 65ae1af75165b6c36daafbe9e9d04e627d943280 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 10:48:21 +0100 Subject: [PATCH 100/112] win experiment --- src/xasync_runner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 448a75bd..d3732523 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -70,7 +70,7 @@ namespace xpyt sys.stdout.write(f"is win: {is_win}\n") sys.stdout.flush() import asyncio - if is_win: + if False and is_win: async def loop_shell(fd_shell, shell_callback, func): try: @@ -189,7 +189,7 @@ namespace xpyt # here we create / ensure we have an event loop loop = asyncio.get_event_loop() - if not is_win: + if True or not is_win: loop.remove_reader(fd_shell) loop.remove_reader(fd_controller) From e7f717d50b61359b45c4923fc34db8df1c13c871 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 11:06:51 +0100 Subject: [PATCH 101/112] win experiment --- src/xasync_runner.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index d3732523..748c6240 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -131,8 +131,11 @@ namespace xpyt try: run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func) except Exception as e: - func(f"Exception in run_main: {e}") - + # get full traceback + import traceback + traceback_str = traceback.format_exc() + func(f"Exception in run_main: {traceback_str}" + )", m_global_dict); py::object run_func = m_global_dict["run_main"]; From efaca5424f02310bb8c65a36ffdb0ba2e64cf1da Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 11:09:19 +0100 Subject: [PATCH 102/112] win experiment --- src/xasync_runner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 748c6240..23d0204d 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -134,8 +134,8 @@ namespace xpyt # get full traceback import traceback traceback_str = traceback.format_exc() - func(f"Exception in run_main: {traceback_str}" - + func(f"Exception in run_main: {traceback_str}") + )", m_global_dict); py::object run_func = m_global_dict["run_main"]; From 329b34a9f75cb637824ea19351cb46a1c02ffe90 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 11:22:30 +0100 Subject: [PATCH 103/112] use selector event loop --- src/xasync_runner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 23d0204d..8c31c84c 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -66,6 +66,8 @@ namespace xpyt import sys is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") print("is_win:", is_win) + if is_win: + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) sys.stdout.write(f"is win: {is_win}\n") sys.stdout.flush() From 3ee6bc8be27a7185d6038e12ae09d890e250fbd0 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 13:33:36 +0100 Subject: [PATCH 104/112] win experiment --- src/xasync_runner.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 8c31c84c..2ef3d708 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -66,12 +66,23 @@ namespace xpyt import sys is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") print("is_win:", is_win) + import asyncio + if is_win: asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) sys.stdout.write(f"is win: {is_win}\n") sys.stdout.flush() - import asyncio + + class ZMQSockReader: + def __init__(self, fd): + self._fd = fd + + def fileno(self): + # This allows asyncio's select to see the handle + return self._fd + + if False and is_win: async def loop_shell(fd_shell, shell_callback, func): @@ -124,6 +135,10 @@ namespace xpyt # here we create / ensure we have an event loop loop = asyncio.get_event_loop() + if is_win: + fd_shell = ZMQSockReader(fd_shell) + fd_controller = ZMQSockReader(fd_controller) + loop.add_reader(fd_shell, shell_callback) loop.add_reader(fd_controller, controller_callback) @@ -195,6 +210,10 @@ namespace xpyt # here we create / ensure we have an event loop loop = asyncio.get_event_loop() if True or not is_win: + + if is_win: + fd_shell = ZMQSockReader(fd_shell) + fd_controller = ZMQSockReader(fd_controller) loop.remove_reader(fd_shell) loop.remove_reader(fd_controller) From 7f438e90893d14229e66dec050a62424652f91a8 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 13:44:33 +0100 Subject: [PATCH 105/112] win experiment --- src/xasync_runner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 2ef3d708..11539592 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -67,7 +67,7 @@ namespace xpyt is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") print("is_win:", is_win) import asyncio - + if is_win: asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) @@ -139,8 +139,10 @@ namespace xpyt fd_shell = ZMQSockReader(fd_shell) fd_controller = ZMQSockReader(fd_controller) + func("Adding readers to event loop") loop.add_reader(fd_shell, shell_callback) loop.add_reader(fd_controller, controller_callback) + func("Running event loop forever") loop.run_forever() From 15abfedbe64062d2a726e15f92c71364c4ce10e6 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 17:14:33 +0100 Subject: [PATCH 106/112] adding default runner to xeus python st. we can add cout stuff --- CMakeLists.txt | 3 + .../xeus-python/xacontrol_default_runner.hpp | 35 ++++ src/xacontrol_default_runner.cpp | 41 +++++ src/xaserver.cpp | 4 +- src/xasync_runner.cpp | 158 +++++++----------- src/xasync_runner.hpp | 2 + 6 files changed, 144 insertions(+), 99 deletions(-) create mode 100644 include/xeus-python/xacontrol_default_runner.hpp create mode 100644 src/xacontrol_default_runner.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ebb7dbd1..0be0d458 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,8 @@ set(XEUS_PYTHON_SRC src/xutils.cpp src/xasync_runner.cpp src/xaserver.cpp + src/xacontrol_default_runner.cpp + ) set(XEUS_PYTHON_HEADERS @@ -194,6 +196,7 @@ set(XEUS_PYTHON_HEADERS include/xeus-python/xtraceback.hpp include/xeus-python/xutils.hpp include/xeus-python/xaserver.hpp + include/xeus-python/xacontrol_default_runner.hpp ) set(XPYTHON_SRC diff --git a/include/xeus-python/xacontrol_default_runner.hpp b/include/xeus-python/xacontrol_default_runner.hpp new file mode 100644 index 00000000..faafca23 --- /dev/null +++ b/include/xeus-python/xacontrol_default_runner.hpp @@ -0,0 +1,35 @@ +/*************************************************************************** +* Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Martin Renou * +* Copyright (c) 2016, QuantStack * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef XEUS_PYTHON_ACONTROL_DEFAULT_RUNNER_HPP +#define XEUS_PYTHON_ACONTROL_DEFAULT_RUNNER_HPP + +#include "xeus_python_config.hpp" +#include "xeus-zmq/xcontrol_runner.hpp" + +namespace xpyt +{ + class XEUS_PYTHON_API xacontrol_default_runner final : public xeus::xcontrol_runner + { + public: + + xacontrol_default_runner() = default; + ~xacontrol_default_runner() override = default; + + private: + + void run_impl() override; + void stop_impl() override; + + bool m_request_stop; + }; +} + +#endif + diff --git a/src/xacontrol_default_runner.cpp b/src/xacontrol_default_runner.cpp new file mode 100644 index 00000000..189b7716 --- /dev/null +++ b/src/xacontrol_default_runner.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** +* Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Martin Renou * +* Copyright (c) 2016, QuantStack * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#include "xeus-python/xacontrol_default_runner.hpp" + +#include + +namespace xpyt +{ + void xacontrol_default_runner::run_impl() + { + std::clog << "Starting control default runner..." << std::endl; + m_request_stop = false; + + while (!m_request_stop) + { + auto msg = read_control(); + if (msg.has_value()) + { + std::cout << "Control default runner received a message." << msg.value().header().dump(4)<< std::endl; + notify_control_listener(std::move(msg.value())); + std::cout << "Notified control listener." << std::endl; + } + } + + stop_channels(); + } + + void xacontrol_default_runner::stop_impl() + { + std::clog << "Stopping control default runner..." << std::endl; + m_request_stop = true; + } +} + diff --git a/src/xaserver.cpp b/src/xaserver.cpp index 804af8fb..d1007e31 100644 --- a/src/xaserver.cpp +++ b/src/xaserver.cpp @@ -1,7 +1,7 @@ #include "xeus-python/xaserver.hpp" #include "xasync_runner.hpp" -#include "xeus-zmq/xcontrol_default_runner.hpp" +#include "xeus-python/xacontrol_default_runner.hpp" #include "xeus-zmq/xserver_zmq_split.hpp" #include "xeus/xkernel.hpp" @@ -31,7 +31,7 @@ namespace xpyt context, config, eh, - std::make_unique(), + std::make_unique(), std::make_unique(globals) ); }; diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 11539592..68a96647 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -22,7 +22,8 @@ namespace xpyt xasync_runner::xasync_runner(py::dict globals) : xeus::xshell_runner(), - m_global_dict{globals} + m_global_dict{globals}, + m_use_busy_loop{true} { std::cout<< "xasync_runner created" << std::endl; } @@ -30,14 +31,9 @@ namespace xpyt void xasync_runner::run_impl() { std::cout << "get descriptors "<< std::endl; - //#ifndef _WIN32 int fd_shell_int = static_cast(this->get_shell_fd()); int fd_controller_int = static_cast(this-> get_shell_controller_fd()); - // #else - // // just use placeholders on Windows - // int fd_shell_int = 0; - // int fd_controller_int = 0; - // #endif + std::cout << "Got descriptors: " << fd_shell_int << ", " << fd_controller_int << std::endl; @@ -55,24 +51,25 @@ namespace xpyt py::gil_scoped_acquire acquire; - auto func = py::cpp_function([]( + // the usual print function is not working for debugging since + // its replaced by the kernel's stdout handling, so we define + // a custom function that writes to sys.stdout directly + auto raw_print = py::cpp_function([]( std::string msg ) { std::cout << "Received message in Python: " << msg << std::endl; }); exec(R"( - import sys - is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") - print("is_win:", is_win) import asyncio + import traceback + + is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") if is_win: asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) - sys.stdout.write(f"is win: {is_win}\n") - sys.stdout.flush() class ZMQSockReader: def __init__(self, fd): @@ -81,85 +78,63 @@ namespace xpyt def fileno(self): # This allows asyncio's select to see the handle return self._fd + + def make_fd(fd): + if is_win: + return ZMQSockReader(fd) + else: + return fd - if False and is_win: - - async def loop_shell(fd_shell, shell_callback, func): - try: - func("Starting shell loop on Windows") - while True: - await asyncio.sleep(0) - func("polling for shell message") - shell_callback() - func("done polling for shell message") - except Exception as e: - func(f"Exception in loop_shell: {e}") - async def loop_controller(fd_controller, controller_callback, func): - try: - func("Starting controller loop on Windows") - while True: - await asyncio.sleep(0) - func("polling for controller message") - controller_callback() - func("done polling for controller message") - except Exception as e: - func(f"Exception in loop_controller: {e}") - - - def run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func): - func("Starting async loop on Windows") - # here we create / ensure we have an event loop - try: - loop = asyncio.get_event_loop() - except Exception as e: - func(f"Exception getting event loop: {e}") - loop = asyncio.get_event_loop() + async def busy_loop(fd, callback, name, raw_print): + try: + raw_print(f"Starting busy loop {name} ") + while True: + await asyncio.sleep(0) + callback() + except Exception as e: + raw_print(f"Exception in busy_loop {name} : {e}") - func("Creating tasks for shell and controller") - task_shell = loop.create_task(loop_shell(fd_shell, shell_callback, func)) + def run_main_busy_loop(fd_shell, fd_controller, shell_callback, controller_callback, raw_print): + raw_print("Creating event loop busy loop") + loop = asyncio.get_event_loop() - func("Creating task for controller") - task_controller = loop.create_task(loop_controller(fd_controller, controller_callback, func)) - - func("Running event loop forever") - try: - loop.run_forever() - except Exception as e: - func(f"Exception in event loop: {e}") - finally: - func("Event loop has stopped") - else: - def run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func): - - # here we create / ensure we have an event loop - loop = asyncio.get_event_loop() - - if is_win: - fd_shell = ZMQSockReader(fd_shell) - fd_controller = ZMQSockReader(fd_controller) - - func("Adding readers to event loop") - loop.add_reader(fd_shell, shell_callback) - loop.add_reader(fd_controller, controller_callback) - func("Running event loop forever") - - loop.run_forever() + task_shell = loop.create_task(busy_loop(fd_shell, shell_callback, "shell", raw_print)) + task_controller = loop.create_task(busy_loop(fd_controller, controller_callback, "controller", raw_print)) + + raw_print("Running event loop forever") + loop.run_forever() - def run_main(fd_shell, fd_controller, shell_callback, controller_callback, func): + + def run_main_non_busy_loop(fd_shell, fd_controller, shell_callback, controller_callback, raw_print): + raw_print("Creating event loop non-busy loop") + # here we create / ensure we have an event loop + loop = asyncio.get_event_loop() + raw_print("Adding readers to event loop") + loop.add_reader(fd_shell, shell_callback) + loop.add_reader(fd_controller, controller_callback) + raw_print("Running event loop forever") + loop.run_forever() + + def run_main(fd_shell, fd_controller, shell_callback, controller_callback, use_busy_loop, raw_print): try: - run_main_impl(fd_shell, fd_controller, shell_callback, controller_callback, func) + fd_controller = make_fd(fd_controller) + fd_shell = make_fd(fd_shell) + + main = run_main_busy_loop if use_busy_loop else run_main_non_busy_loop + main(fd_shell, fd_controller, shell_callback, controller_callback, raw_print) + except Exception as e: # get full traceback - import traceback + traceback_str = traceback.format_exc() - func(f"Exception in run_main: {traceback_str}") + raw_print(f"Exception in run_main: {traceback_str}") )", m_global_dict); py::object run_func = m_global_dict["run_main"]; std::cout << "Starting async loop "<< std::endl; - run_func(fd_shell_int, fd_controller_int, shell_callback, controller_callback, func); + run_func(fd_shell_int, fd_controller_int, shell_callback, controller_callback, m_use_busy_loop, raw_print); } @@ -189,14 +164,9 @@ namespace xpyt std::cout << "get descriptors to stop"<< std::endl; - #ifndef _WIN32 - int fd_shell_int = static_cast(this->get_shell_fd()); - int fd_controller_int = static_cast(this-> get_shell_controller_fd()); - #else - // just use placeholders on Windows - int fd_shell_int = 0; - int fd_controller_int = 0; - #endif + int fd_shell_int = static_cast(this->get_shell_fd()); + int fd_controller_int = static_cast(this-> get_shell_controller_fd()); + py::gil_scoped_acquire acquire; @@ -205,26 +175,20 @@ namespace xpyt import asyncio import sys - def stop_loop(fd_shell, fd_controller): - is_win = sys.platform.startswith("win") or sys.platform.startswith("cygwin") or sys.platform.startswith("msys") + def stop_loop(fd_shell, fd_controller, use_busy_loop): # here we create / ensure we have an event loop loop = asyncio.get_event_loop() - if True or not is_win: - - if is_win: - fd_shell = ZMQSockReader(fd_shell) - fd_controller = ZMQSockReader(fd_controller) - loop.remove_reader(fd_shell) - loop.remove_reader(fd_controller) - + if not use_busy_loop: + loop.remove_reader(make_fd(fd_shell)) + loop.remove_reader(make_fd(fd_controller)) loop.stop() )", m_global_dict); py::object stop_func = m_global_dict["stop_loop"]; - stop_func(fd_shell_int, fd_controller_int); + stop_func(fd_shell_int, fd_controller_int, m_use_busy_loop); } else diff --git a/src/xasync_runner.hpp b/src/xasync_runner.hpp index 12dbd771..f76ebd54 100644 --- a/src/xasync_runner.hpp +++ b/src/xasync_runner.hpp @@ -43,6 +43,8 @@ namespace xpyt py::dict m_global_dict; + bool m_use_busy_loop; + }; From 69ab3dcd7a0efa66777ccbf48e285f5ca4237701 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Mon, 19 Jan 2026 17:26:40 +0100 Subject: [PATCH 107/112] missing break --- src/xacontrol_default_runner.cpp | 1 + src/xasync_runner.cpp | 1 + test/CMakeLists.txt | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/xacontrol_default_runner.cpp b/src/xacontrol_default_runner.cpp index 189b7716..d1f7c169 100644 --- a/src/xacontrol_default_runner.cpp +++ b/src/xacontrol_default_runner.cpp @@ -28,6 +28,7 @@ namespace xpyt std::cout << "Notified control listener." << std::endl; } } + std::clog << "Exiting control default runner loop." << std::endl; stop_channels(); } diff --git a/src/xasync_runner.cpp b/src/xasync_runner.cpp index 68a96647..887313a5 100644 --- a/src/xasync_runner.cpp +++ b/src/xasync_runner.cpp @@ -189,6 +189,7 @@ namespace xpyt py::object stop_func = m_global_dict["stop_loop"]; stop_func(fd_shell_int, fd_controller_int, m_use_busy_loop); + break; } else diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d5fafe2c..d1a3e5ca 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,7 +12,7 @@ # ========== cmake_minimum_required(VERSION 3.20) - +enable_testing() if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(xeus-python-test) @@ -57,6 +57,7 @@ set(XEUS_PYTHON_TESTS add_executable(test_xeus_python ${XEUS_PYTHON_TESTS}) + target_compile_features(test_xeus_python PRIVATE cxx_std_17) if (APPLE) From a5692286af8ee4d56c532823dbbbd1a39c8860b1 Mon Sep 17 00:00:00 2001 From: DerThorsten Date: Tue, 20 Jan 2026 08:56:31 +0100 Subject: [PATCH 108/112] cleanup --- .github/workflows/deploy-github-page.yml | 5 ----- .github/workflows/main.yml | 14 +------------- include/xeus-python/xinterpreter.hpp | 16 +--------------- src/main.cpp | 23 +++-------------------- 4 files changed, 5 insertions(+), 53 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 6929951a..43737206 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -33,7 +33,6 @@ jobs: environment-file: environment-wasm-build.yml init-shell: bash environment-name: xeus-python-wasm-build - - name: Set ncpus run: echo "ncpus=$(nproc --all)" >> $GITHUB_ENV @@ -51,7 +50,6 @@ jobs: URL=https://github.com/DerThorsten/xeus-python-shell/archive/refs/heads/libuv.zip curl -L $URL -o xeus-python-shell-libuv.zip unzip xeus-python-shell-libuv.zip - export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-python-wasm-host echo "PREFIX=$PREFIX" >> $GITHUB_ENV @@ -66,9 +64,6 @@ jobs: emmake make -j${{ env.ncpus }} install - - - - name: Jupyter Lite integration shell: bash -l {0} run: | diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7ca488f1..24d58632 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,13 +66,6 @@ jobs: ${{ env.CMAKE_EXTRA_ARGS }} working-directory: build - # - name: Build - # run: cmake --build . --target xeus-python --verbose -j ${{ runner.os == 'macOS' && 3 || 4 }} - # working-directory: build - - # - name: Inspect build lib - # run: nm build/libxeus-python.so | grep raw_interpreter - - name: Build all targets run: cmake --build . --verbose -j ${{ runner.os == 'macOS' && 3 || 4 }} working-directory: build @@ -118,7 +111,6 @@ jobs: shell: cmd /C call {0} run: pip install git+https://github.com/DerThorsten/xeus-python-shell.git@libuv - - name: Static build option if: matrix.build_type == 'static_build' run: | @@ -163,8 +155,4 @@ jobs: run: | test_xeus_python timeout-minutes: 4 - working-directory: build\test - - - - + working-directory: build\test \ No newline at end of file diff --git a/include/xeus-python/xinterpreter.hpp b/include/xeus-python/xinterpreter.hpp index 378c3b29..c8e2a9d6 100644 --- a/include/xeus-python/xinterpreter.hpp +++ b/include/xeus-python/xinterpreter.hpp @@ -101,21 +101,7 @@ namespace xpyt bool m_redirect_output_enabled; bool m_redirect_display_enabled; - private: - - // helper methods: - void execute_request_impl_sync(send_reply_callback cb, - int execution_counter, - const std::string& code, - xeus::execute_request_config config, - nl::json user_expressions); - - void execute_request_impl_async(send_reply_callback cb, - int execution_counter, - const std::string& code, - xeus::execute_request_config config, - nl::json user_expressions); - + private: virtual void instanciate_ipython_shell(); virtual bool use_jedi_for_completion() const; diff --git a/src/main.cpp b/src/main.cpp index 577d8f09..55615502 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,14 +122,9 @@ int main(int argc, char* argv[]) std::unique_ptr context = xeus::make_zmq_context(); - - - + // we want to use **the same global dict everywhere** py::dict globals = py::globals(); - - - // Instantiating the xeus xinterpreter bool raw_mode = xpyt::extract_option("-r", "--raw", argc, argv); using interpreter_ptr = std::unique_ptr; @@ -159,11 +154,7 @@ int main(int argc, char* argv[]) debugger_config["python"] = executable; - - - - - + // Factory to create the debugger with the global dict auto make_the_debugger = [globals]( xeus::xcontext& context, const xeus::xconfiguration& config, @@ -179,15 +170,7 @@ int main(int argc, char* argv[]) session_id, debugger_config); }; - - - - - - - - - + if (!connection_filename.empty()) { xeus::xconfiguration config = xeus::load_configuration(connection_filename); From 6ad6c0542c833eecbe7ca747335002355b34ebc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 22 Jan 2026 08:30:27 +0100 Subject: [PATCH 109/112] applied #685 to async pr --- test/CMakeLists.txt | 5 +++- test/test_debugger.cpp | 57 +++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d1a3e5ca..d73955d0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,6 +45,9 @@ endif() find_package(Threads) find_package(doctest) +cmake_policy(SET CMP0167 OLD) # use find boost from old cmake +find_package(Boost REQUIRED COMPONENTS process filesystem) + include_directories(${GTEST_INCLUDE_DIRS} SYSTEM) set(XEUS_PYTHON_TESTS @@ -71,7 +74,7 @@ set_target_properties(test_xeus_python PROPERTIES ) include_directories(${PYTHON_INCLUDE_DIRS}) -target_link_libraries(test_xeus_python ${PYTHON_LIBRARIES} xeus-zmq doctest::doctest ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(test_xeus_python ${PYTHON_LIBRARIES} xeus-zmq doctest::doctest Boost::headers Boost::filesystem Boost::process ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(test_xeus_python PRIVATE ${XEUS_PYTHON_INCLUDE_DIR}) add_custom_target(xtest COMMAND test_xeus_python DEPENDS test_xeus_python) diff --git a/test/test_debugger.cpp b/test/test_debugger.cpp index f468a082..9fd1bbd1 100644 --- a/test/test_debugger.cpp +++ b/test/test_debugger.cpp @@ -35,6 +35,11 @@ #include #endif +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include + /*********************************** * Should be moved in a utils file * ***********************************/ @@ -1147,19 +1152,25 @@ void dump_connection_file() } } -void start_kernel() +struct KernelProcess { - dump_connection_file(); - std::string cmd = "xpython -f " + KERNEL_JSON + "&"; - int ret2 = std::system(cmd.c_str()); - std::this_thread::sleep_for(4s); -} + KernelProcess() + { + std::this_thread::sleep_for(2s); + } + +private: + + bool _ = [] { dump_connection_file(); return true; }(); + boost::asio::io_context ctx; + boost::process::process process{ ctx, boost::process::environment::find_executable("xpython"), { "-f" , KERNEL_JSON } }; +}; TEST_SUITE("debugger") { TEST_CASE("init") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1176,7 +1187,7 @@ TEST_SUITE("debugger") TEST_CASE("disconnect") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1192,7 +1203,7 @@ TEST_SUITE("debugger") TEST_CASE("attach") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1209,7 +1220,7 @@ TEST_SUITE("debugger") TEST_CASE("multisession") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1228,7 +1239,7 @@ TEST_SUITE("debugger") TEST_CASE("set_external_breakpoints") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1247,7 +1258,7 @@ TEST_SUITE("debugger") /* TEST_CASE("external_next_continue") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1264,7 +1275,7 @@ TEST_SUITE("debugger") */ TEST_CASE("set_breakpoints") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1281,7 +1292,7 @@ TEST_SUITE("debugger") TEST_CASE("set_exception_breakpoints") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1298,7 +1309,7 @@ TEST_SUITE("debugger") TEST_CASE("source") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1317,7 +1328,7 @@ TEST_SUITE("debugger") /* TEST_CASE("next_continue") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1337,7 +1348,7 @@ TEST_SUITE("debugger") /* TEST_CASE("stepin") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1355,7 +1366,7 @@ TEST_SUITE("debugger") TEST_CASE("stack_trace") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1372,7 +1383,7 @@ TEST_SUITE("debugger") TEST_CASE("debug_info") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1389,7 +1400,7 @@ TEST_SUITE("debugger") TEST_CASE("inspect_variables") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1408,7 +1419,7 @@ TEST_SUITE("debugger") /* TEST_CASE("rich_inspect_variables") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1425,7 +1436,7 @@ TEST_SUITE("debugger") TEST_CASE("variables") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { @@ -1442,7 +1453,7 @@ TEST_SUITE("debugger") TEST_CASE("copy_to_globals") { - start_kernel(); + KernelProcess xpython_process; timer t; auto context_ptr = xeus::make_zmq_context(); { From 79b7d72bf3cfa1d890be1633f54fe6a326c7989c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 22 Jan 2026 09:45:10 +0100 Subject: [PATCH 110/112] added missing boost dependency --- environment-dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment-dev.yml b/environment-dev.yml index 7fc0d645..675927b7 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -26,3 +26,4 @@ dependencies: - jupyter_kernel_test<0.8 - doctest - pluggy=1.3 + - libboost From 7804a3a2ce1a44bd321e5cfbdd32f2d2385384f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 22 Jan 2026 05:19:02 +0100 Subject: [PATCH 111/112] ignore root build dirs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 041239f7..97eb65ac 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ docs/build/ # Build directory build/ +/build-*/ # generated kernel specs /share/jupyter/kernels/xpython/kernel.json From 64e2281164071d45b19e18c3b86dc93aec4d558a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 22 Jan 2026 10:04:11 +0100 Subject: [PATCH 112/112] added missing boost packages dependencies --- environment-dev.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/environment-dev.yml b/environment-dev.yml index 675927b7..1c0df0c6 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -27,3 +27,6 @@ dependencies: - doctest - pluggy=1.3 - libboost + - libboost-devel + - libboost-headers +