From 5eb3ea4b1267911c87005038be2e71d0c9a2bee5 Mon Sep 17 00:00:00 2001 From: Aatu Alatervo Date: Tue, 17 Jan 2023 12:52:28 +0000 Subject: [PATCH] Improve support for multithreading by releasing the GIL for a number of different calls into c++ turbodbc library --- .../Library/src/python_bindings/connect.cpp | 2 +- .../Library/src/python_bindings/connection.cpp | 8 ++++---- .../Library/src/python_bindings/cursor.cpp | 9 +++------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/cpp/turbodbc_python/Library/src/python_bindings/connect.cpp b/cpp/turbodbc_python/Library/src/python_bindings/connect.cpp index e72369332..77d6e9592 100644 --- a/cpp/turbodbc_python/Library/src/python_bindings/connect.cpp +++ b/cpp/turbodbc_python/Library/src/python_bindings/connect.cpp @@ -6,7 +6,7 @@ namespace turbodbc { namespace bindings { void for_connect(pybind11::module & module) { - module.def("connect", turbodbc::connect); + module.def("connect", turbodbc::connect, pybind11::call_guard()); } } } diff --git a/cpp/turbodbc_python/Library/src/python_bindings/connection.cpp b/cpp/turbodbc_python/Library/src/python_bindings/connection.cpp index 89fa93bb6..d0e8ccce5 100644 --- a/cpp/turbodbc_python/Library/src/python_bindings/connection.cpp +++ b/cpp/turbodbc_python/Library/src/python_bindings/connection.cpp @@ -7,10 +7,10 @@ namespace turbodbc { namespace bindings { void for_connection(pybind11::module &module) { pybind11::class_(module, "Connection") - .def("commit", &turbodbc::connection::commit) - .def("rollback", &turbodbc::connection::rollback) - .def("cursor", &turbodbc::connection::make_cursor) - .def("set_autocommit", &turbodbc::connection::set_autocommit) + .def("commit", &turbodbc::connection::commit, pybind11::call_guard()) + .def("rollback", &turbodbc::connection::rollback, pybind11::call_guard()) + .def("cursor", &turbodbc::connection::make_cursor, pybind11::call_guard()) + .def("set_autocommit", &turbodbc::connection::set_autocommit, pybind11::call_guard()) .def("autocommit_enabled", &turbodbc::connection::autocommit_enabled) ; diff --git a/cpp/turbodbc_python/Library/src/python_bindings/cursor.cpp b/cpp/turbodbc_python/Library/src/python_bindings/cursor.cpp index d0e1f1524..ecd28436a 100644 --- a/cpp/turbodbc_python/Library/src/python_bindings/cursor.cpp +++ b/cpp/turbodbc_python/Library/src/python_bindings/cursor.cpp @@ -8,12 +8,9 @@ namespace turbodbc { namespace bindings { void for_cursor(pybind11::module & module) { pybind11::class_(module, "Cursor") - .def("prepare", &turbodbc::cursor::prepare) - .def("execute", [](turbodbc::cursor& cursor) { - pybind11::gil_scoped_release release; - cursor.execute(); - }) - .def("_reset", &turbodbc::cursor::reset) + .def("prepare", &turbodbc::cursor::prepare, pybind11::call_guard()) + .def("execute", &turbodbc::cursor::execute, pybind11::call_guard()) + .def("_reset", &turbodbc::cursor::reset, pybind11::call_guard()) .def("get_row_count", &turbodbc::cursor::get_row_count) .def("get_result_set", &turbodbc::cursor::get_result_set) .def("more_results", &turbodbc::cursor::more_results)