From f7935b33b83a9c8e92972862ce8e51471a694b63 Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 29 Apr 2021 12:01:38 +1000 Subject: [PATCH 1/6] pymoos: fix exceptions so the trace is returned to python --- src/pyMOOS.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pyMOOS.cpp b/src/pyMOOS.cpp index 4cddd95..c6b47d6 100644 --- a/src/pyMOOS.cpp +++ b/src/pyMOOS.cpp @@ -79,11 +79,11 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { bool bResult = false; Py_BEGIN_ALLOW_THREADS - // PyGILState_STATE gstate = PyGILState_Ensure(); + // py::gil_scoped_acquire acquire; closing_ = true; bResult = BASE::Close(true); - // PyGILState_Release(gstate); + // py::gil_scoped_release release; Py_END_ALLOW_THREADS return bResult; @@ -94,17 +94,17 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { bool bResult = false; - PyGILState_STATE gstate = PyGILState_Ensure(); + py::gil_scoped_acquire acquire; try { py::object result = on_connect_object_(); bResult = py::bool_(result); } catch (const py::error_already_set& e) { - PyGILState_Release(gstate); + py::gil_scoped_release release; throw pyMOOSException( "OnConnect:: caught an exception thrown in python callback"); } - PyGILState_Release(gstate); + py::gil_scoped_release release; return bResult; @@ -125,19 +125,19 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { bool on_mail() { bool bResult = false; - PyGILState_STATE gstate = PyGILState_Ensure(); + py::gil_scoped_acquire acquire; try { if(!closing_){ py::object result = on_mail_object_(); bResult = py::bool_(result); } } catch (const py::error_already_set& e) { - PyGILState_Release(gstate); + py::gil_scoped_release release; throw pyMOOSException( "OnMail:: caught an exception thrown in python callback"); } - PyGILState_Release(gstate); + py::gil_scoped_release release; return bResult; } @@ -158,19 +158,17 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { } bool bResult = false; + py::gil_scoped_acquire acquire; - PyGILState_STATE gstate = PyGILState_Ensure(); try { py::object result = q->second->func_(M); bResult = py::bool_(result); } catch (const py::error_already_set& e) { - PyGILState_Release(gstate); - throw pyMOOSException( - "ActiveQueue:: caught an exception thrown in python callback"); + py::gil_scoped_release release; + py::print("ActiveQueue:: caught an exception thrown in python callback"); + throw; } - PyGILState_Release(gstate); - return bResult; } From 4a757978b8f29e24f2105054b17dd11e9017e3ec Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 29 Apr 2021 12:23:07 +1000 Subject: [PATCH 2/6] ci: update cibuildwheels version --- .github/workflows/wheels.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index d9a96c4..673cfb8 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -56,7 +56,7 @@ jobs: platforms: all - name: Install cibuildwheel - run: python -m pip install cibuildwheel==1.8.0 + run: python -m pip install cibuildwheel==1.10.0 - name: Checkout MOOS source uses: actions/checkout@v2 @@ -153,7 +153,7 @@ jobs: # - uses: actions/setup-python@v2 # - name: Install cibuildwheel - # run: python -m pip install cibuildwheel==1.6.3 + # run: python -m pip install cibuildwheel==1.10.0 # - uses: ilammy/msvc-dev-cmd@v1 From 42cedbed1b3a9bd93b130ec80f2d2312fdaaa4ce Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 29 Apr 2021 12:49:26 +1000 Subject: [PATCH 3/6] TEMP COMMIT - only build 39 --- .github/workflows/wheels.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 673cfb8..7b5ed48 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -108,6 +108,7 @@ jobs: CIBW_MANYLINUX_I686_IMAGE: manylinux2014 CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014 CIBW_ARCHS_LINUX: "auto aarch64" + CIBW_BUILD: cp39 CIBW_SKIP: cp27-* CIBW_BEFORE_ALL: | mkdir moosbuild; From 3f7563bcb68eca65cbac2334e18358bc17df6e97 Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 29 Apr 2021 13:00:45 +1000 Subject: [PATCH 4/6] fix1 --- src/pyMOOS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyMOOS.cpp b/src/pyMOOS.cpp index c6b47d6..869aa80 100644 --- a/src/pyMOOS.cpp +++ b/src/pyMOOS.cpp @@ -164,8 +164,8 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { py::object result = q->second->func_(M); bResult = py::bool_(result); } catch (const py::error_already_set& e) { - py::gil_scoped_release release; py::print("ActiveQueue:: caught an exception thrown in python callback"); + py::gil_scoped_release release; throw; } From 1eabf94c98e814b4fc21977f6a220fbdc29ea2fa Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 29 Apr 2021 13:08:31 +1000 Subject: [PATCH 5/6] remove exception code. fix spelling mistake --- src/pyMOOS.cpp | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/pyMOOS.cpp b/src/pyMOOS.cpp index 869aa80..e090526 100644 --- a/src/pyMOOS.cpp +++ b/src/pyMOOS.cpp @@ -18,14 +18,6 @@ PYBIND11_MAKE_OPAQUE(CommsStatusVector); namespace py = pybind11; -class pyMOOSException : public std::exception { -public: - explicit pyMOOSException(const char * m) : message{m} {} - virtual const char * what() const noexcept override {return message.c_str();} -private: - std::string message = ""; -}; - namespace MOOS { /** this is a class which wraps MOOS::MOOSAsyncCommClient to provide @@ -100,8 +92,7 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { bResult = py::bool_(result); } catch (const py::error_already_set& e) { py::gil_scoped_release release; - throw pyMOOSException( - "OnConnect:: caught an exception thrown in python callback"); + throw; } py::gil_scoped_release release; @@ -133,8 +124,7 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { } } catch (const py::error_already_set& e) { py::gil_scoped_release release; - throw pyMOOSException( - "OnMail:: caught an exception thrown in python callback"); + throw; } py::gil_scoped_release release; @@ -182,7 +172,7 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { maq->queue_name_ = sQueueName; maq->func_ = func; - std::cerr << "adding active queue OK\n"; + // std::cerr << "adding active queue OK\n"; active_queue_details_[sQueueName] = maq; return BASE::AddActiveQueue(sQueueName, active_queue_delegate, maq); @@ -516,7 +506,7 @@ PYBIND11_MODULE(pymoos, m) { "unified time. Of course, if your process isn't using MOOSComms" "at all, this function works just fine and returns the " "unadulterated time as you would expect.", - py::arg("apply_timewartping") = true); + py::arg("apply_timewarping") = true); m.def("is_little_end_in", &IsLittleEndian, "Return True if current machine is little end in."); m.def("set_moos_timewarp", &SetMOOSTimeWarp, @@ -524,16 +514,4 @@ PYBIND11_MODULE(pymoos, m) { py::arg("warp")); m.def("get_moos_timewarp", &GetMOOSTimeWarp, "Return the current time warp factor."); - - // TODO: double check that it's still needed - static py::exception ex(m, "pyMOOSException"); - py::register_exception_translator([](std::exception_ptr p) { - try { - if (p) std::rethrow_exception(p); - } catch (const pyMOOSException &e) { - // Set pyMOOSException as the active python error - // ex(e.what()); - PyErr_SetString(PyExc_RuntimeError, e.what()); - } - }); } From 5bde6e1fc3966abc39bef2fb53ef6ec807744c37 Mon Sep 17 00:00:00 2001 From: Russ Webber Date: Thu, 29 Apr 2021 13:09:20 +1000 Subject: [PATCH 6/6] TEMP --- .github/workflows/wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 7b5ed48..4eaeec6 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -108,7 +108,7 @@ jobs: CIBW_MANYLINUX_I686_IMAGE: manylinux2014 CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014 CIBW_ARCHS_LINUX: "auto aarch64" - CIBW_BUILD: cp39 + CIBW_BUILD: cp39-manylinux_x86_64 CIBW_SKIP: cp27-* CIBW_BEFORE_ALL: | mkdir moosbuild;