From 82ae2d72222aefcac54a8e88995735ede3abe9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=84=8D=F0=9D=95=A0=F0=9D=95=9D=F0=9D=95=9D=F0=9D=95=A0?= =?UTF-8?q?=F0=9D=95=A8=20=F0=9D=95=84=F0=9D=95=92=F0=9D=95=9F?= Date: Fri, 28 Feb 2025 09:35:08 +0200 Subject: [PATCH] Make gloo context `setTimeout` `getTimeout` callable from Python (#34) For now, if we directly call `setTimeout` or `getTimeout` from Python, it will throw the parameter unmatch error, this PR addresses this by using a wrapper around the original function. Signed-off-by: Hollow Man --- pygloo/main.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pygloo/main.cc b/pygloo/main.cc index 8946434..0707a6b 100644 --- a/pygloo/main.cc +++ b/pygloo/main.cc @@ -8,11 +8,20 @@ #include #include #include +#include namespace pygloo { bool transport_tcp_available() { return GLOO_HAVE_TRANSPORT_TCP; } bool transport_uv_available() { return GLOO_HAVE_TRANSPORT_UV; } + +void setTimeout_wrapper(gloo::Context* context, int timeout_ms) { + context->setTimeout(std::chrono::milliseconds(timeout_ms)); +} + +int64_t getTimeout_wrapper(gloo::Context* context) { + return context->getTimeout().count(); +} } // namespace pygloo PYBIND11_MODULE(pygloo, m) { @@ -124,8 +133,8 @@ PYBIND11_MODULE(pygloo, m) { .def("createUnboundBuffer", &gloo::Context::createUnboundBuffer) .def("nextSlot", &gloo::Context::nextSlot) .def("closeConnections", &gloo::Context::closeConnections) - .def("setTimeout", &gloo::Context::setTimeout) - .def("getTimeout", &gloo::Context::getTimeout); + .def("setTimeout", &pygloo::setTimeout_wrapper) + .def("getTimeout", &pygloo::getTimeout_wrapper); pygloo::transport::def_transport_module(m); pygloo::rendezvous::def_rendezvous_module(m);