-
Hello there! I'm working on acquiring and releasing the GIL correctly using This is my code: void runScript()
{
if (script.empty()) return;
py::gil_scoped_acquire acquire;
py::module entity_module("entity_module");
py::class_<Entity>(entity_module, "Entity")
.def(py::init<>())
.def_readwrite("name", &Entity::name)
.def_readwrite("position", &Entity::position)
.def_readwrite("scale", &Entity::scale)
.def_readwrite("rotation", &Entity::rotation)
.def_readwrite("color", &Entity::color)
.def_readwrite("visible", &Entity::visible)
.def_readwrite("collider", &Entity::collider);
py::object entity_obj = py::cast(this);
py::module input_module = py::module::import("input_module");
py::module collisions_module = py::module::import("collisions_module");
py::module camera_module = py::module::import("camera_module");
auto locals = py::dict("entity"_a=entity_obj,
"IsMouseButtonPressed"_a=input_module.attr("IsMouseButtonPressed"),
"IsKeyDown"_a=input_module.attr("IsKeyDown"),
"KeyboardKey"_a=input_module.attr("KeyboardKey"),
"raycast"_a=collisions_module.attr("raycast"),
"camera"_a=py::cast(&camera));
try
{
string script_content = read_file_to_string(script);
py::gil_scoped_acquire acquire;
auto execute_script = [&script_content, &locals]() {
py::exec(script_content, py::globals(), locals);
};
// Create a TBB task group
tbb::task_group tg;
tg.run(execute_script);
// Wait for all the tasks to complete
tg.wait();
} catch (const py::error_already_set& e) {
py::print(e.what());
}
py::gil_scoped_release release1;
}
I also tried async and using a normal pthread but no luck, that is why I tried |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Closing for inactivity |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
How did you solve this |
Beta Was this translation helpful? Give feedback.
Hi there. I found out what was causing the issue some while ago and with a bit of modification it seems to be working now. Thank you