Make sure that the GIL is held when raising an exception. (#8501)

diff --git a/bindings/python/iree/runtime/vm.cc b/bindings/python/iree/runtime/vm.cc
index 68b7522..34cb5aa 100644
--- a/bindings/python/iree/runtime/vm.cc
+++ b/bindings/python/iree/runtime/vm.cc
@@ -115,11 +115,14 @@
 
 void VmContext::Invoke(iree_vm_function_t f, VmVariantList& inputs,
                        VmVariantList& outputs) {
-  py::gil_scoped_release release;
-  CheckApiStatus(iree_vm_invoke(raw_ptr(), f, IREE_VM_INVOCATION_FLAG_NONE,
-                                nullptr, inputs.raw_ptr(), outputs.raw_ptr(),
-                                iree_allocator_system()),
-                 "Error invoking function");
+  iree_status_t status;
+  {
+    py::gil_scoped_release release;
+    status = iree_vm_invoke(raw_ptr(), f, IREE_VM_INVOCATION_FLAG_NONE, nullptr,
+                            inputs.raw_ptr(), outputs.raw_ptr(),
+                            iree_allocator_system());
+  }
+  CheckApiStatus(status, "Error invoking function");
 }
 
 //------------------------------------------------------------------------------