Skip to content

Commit ee22437

Browse files
committed
Ensure GIL is released solely for build phase to fix errors from new pybind version
1 parent 6a28961 commit ee22437

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/python_interface/python_interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "python_interface/python_interface.hpp"
3131
#include "fs_node.hpp"
3232
#include "scan_cpp.hpp"
33+
#include "taskmaster.hpp"
3334

3435
#include "python_interface/python_interface_internal.hpp"
3536
#include "python_interface/sconscript.hpp"
@@ -253,13 +254,12 @@ PYBIND11_EMBEDDED_MODULE(SCons, m_scons)
253254

254255
PyDict_Update(main_namespace().ptr(), m_script.attr("__dict__").ptr());
255256

256-
static py::gil_scoped_release unlock{};
257+
sconspp::pre_build_hook = []() -> void* { return new py::gil_scoped_release; };
258+
sconspp::post_build_hook = [](void* release) { delete reinterpret_cast<py::gil_scoped_release*>(release); };
257259
}
258260

259261
void run_script(const std::string& filename, std::vector<std::string> command_line_target_strings)
260262
{
261-
py::gil_scoped_acquire lock{};
262-
263263
try {
264264
main_namespace()["COMMAND_LINE_TARGETS"] = py::cast(command_line_target_strings);
265265

src/taskmaster.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ namespace sconspp
129129
bool always_build;
130130
bool keep_going;
131131

132+
std::function<void*()> pre_build_hook;
133+
std::function<void(void*)> post_build_hook;
134+
132135
void build_order(Node end_goal, BuildOrder& output)
133136
{
134137
std::map<Node, boost::default_color_type> colors;
@@ -278,10 +281,13 @@ namespace sconspp
278281

279282
int build(Node end_goal)
280283
{
284+
void* hook_data = pre_build_hook ? pre_build_hook() : nullptr;
281285
BuildOrder nodes;
282286
build_order(end_goal, nodes);
283287
PersistentData& db = get_global_db();
284288

285-
return parallel_build(nodes, db);
289+
int result = parallel_build(nodes, db);
290+
if(post_build_hook) post_build_hook(hook_data);
291+
return result;
286292
}
287293
}

src/taskmaster.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ namespace sconspp
3131
extern bool always_build;
3232
extern bool keep_going;
3333

34+
extern std::function<void*()> pre_build_hook;
35+
extern std::function<void(void*)> post_build_hook;
36+
3437
int build(Node end_goal);
3538

3639
void build_order(Node end_goal, std::vector<Node>& nodes);

0 commit comments

Comments
 (0)