Release GIL in MuJoCo Studio Python bindings.

This change adds py::gil_scoped_release to various functions in the parser, renderer, sim and ux modules of the MuJoCo Studio Python bindings. This allows other Python threads to execute while these C++ functions, which can sometimes be time-consuming, are running. The two heaviest operations Present() (rendering) and Advance() (physics) now both release the GIL in C++.

PiperOrigin-RevId: 930645361
Change-Id: Ib239fb54edc7ac0d8b1d94bec8c57a447d5f4d27
This commit is contained in:
Matija Kecman
2026-06-11 11:31:28 -07:00
committed by Copybara-Service
parent ab17ff5552
commit 37084a5c0b
4 changed files with 46 additions and 6 deletions
+6 -1
View File
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <memory>
#include <string_view>
#include <mujoco/mujoco.h>
@@ -24,7 +25,11 @@ namespace mujoco::python {
// Loads, parses, and compiles a MuJoCo model from the given file. Returns the
// python mjData object (which also contains the compiled mjModel).
py::object Parse(std::string_view filepath) {
auto holder = platform::ModelHolder::FromFile(filepath);
std::unique_ptr<platform::ModelHolder> holder;
{
py::gil_scoped_release no_gil;
holder = platform::ModelHolder::FromFile(filepath);
}
if (!holder->ok()) {
throw py::value_error(
std::string("Failed to load model from '") +