summaryrefslogtreecommitdiffstats
path: root/python/guestfs-py-byhand.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-04-22 22:53:07 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-04-22 22:53:07 +0100
commitf24494195ab8541fda7236afb37a4f897c9bcee5 (patch)
tree917165dc9d1387ca76a3bb5262478f06e51ad9b7 /python/guestfs-py-byhand.c
parentdfd7efb91fb3120937c4780fee943abd0351c20e (diff)
downloadlibguestfs-f24494195ab8541fda7236afb37a4f897c9bcee5.tar.gz
libguestfs-f24494195ab8541fda7236afb37a4f897c9bcee5.tar.xz
libguestfs-f24494195ab8541fda7236afb37a4f897c9bcee5.zip
python: Ensure Python GIL state is correct during callback.
This updates commit 2cac52000a6a96a583af72e289a4296c596047d5.
Diffstat (limited to 'python/guestfs-py-byhand.c')
-rw-r--r--python/guestfs-py-byhand.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/python/guestfs-py-byhand.c b/python/guestfs-py-byhand.c
index af9686fc..29be83b7 100644
--- a/python/guestfs-py-byhand.c
+++ b/python/guestfs-py-byhand.c
@@ -91,6 +91,7 @@ py_guestfs_event_callback_wrapper (guestfs_h *g,
const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
+ PyGILState_STATE py_save = PyGILState_UNLOCKED;
PyObject *py_callback = callback;
PyObject *py_array;
PyObject *args;
@@ -109,7 +110,14 @@ py_guestfs_event_callback_wrapper (guestfs_h *g,
(unsigned PY_LONG_LONG) event, event_handle,
buf, buf_len, py_array);
+ if (PyEval_ThreadsInitialized ())
+ py_save = PyGILState_Ensure ();
+
py_r = PyEval_CallObject (py_callback, args);
+
+ if (PyEval_ThreadsInitialized ())
+ PyGILState_Release (py_save);
+
Py_DECREF (args);
if (py_r != NULL)