[PATCH] Python: Release GIL on blocking operations
John (J5) Palmieri
johnp at redhat.com
Thu Aug 3 13:30:42 PDT 2006
Cool thanks. Do you think you could get your client and server into the
regression tests?
On Wed, 2006-08-02 at 15:35 +0800, Justin Mazzola Paluska wrote:
> Hi,
>
> I noticed that the D-Bus Python bindings don't release the global
> interpreter lock (GIL) when they block. This causes all threads that
> need the Python interpreter to block until the D-Bus call returns.
> The attached patch releases/acquires the GIL around blocking D-Bus
> operations.
>
> I noticed this in another application I was writing, but have attached
> minimal examples of why it's necessary. Without the patch, the thread
> printing *'s doesn't run; with the patch, the thread printing *'s runs
> while the D-Bus thread is blocked.
>
> Should I file a bug in the tracker with the patches?
> --Justin
> plain text document attachment (python-release-gil-on-block.patch)
> diff --git a/dbus/dbus_bindings.pyx b/dbus/dbus_bindings.pyx
> index c29dea2..bc0f78a 100644
> --- a/dbus/dbus_bindings.pyx
> +++ b/dbus/dbus_bindings.pyx
> @@ -25,6 +25,9 @@ cdef extern from "Python.h":
> void PyErr_Clear()
> PyGILState_STATE PyGILState_Ensure()
> void PyGILState_Release(PyGILState_STATE)
> + struct PyThreadState
> + PyThreadState* PyEval_SaveThread()
> + void PyEval_RestoreThread(PyThreadState *tstate)
>
> ctypedef struct DBusError:
> char *name
> @@ -438,16 +441,22 @@ cdef class Connection:
> cdef DBusError error
> cdef DBusMessage *msg
> cdef Message m
> + cdef PyThreadState *_save
> + cdef int int_timeout_milliseconds
>
> dbus_error_init(&error)
>
> msg = message._get_msg()
>
> + int_timeout_milliseconds = timeout_milliseconds
> + _save = PyEval_SaveThread()
> + # NOTE: Don't use Python code until RestoreThread
> retval = dbus_connection_send_with_reply_and_block(
> self.conn,
> msg,
> - timeout_milliseconds,
> + int_timeout_milliseconds,
> &error)
> + PyEval_RestoreThread(_save)
>
> if dbus_error_is_set(&error):
> errormsg = error.message
> @@ -629,7 +638,11 @@ cdef class PendingCall:
> return message
>
> def block(self):
> + cdef PyThreadState *_save
> + _save = PyEval_SaveThread()
> + # NOTE: Don't use Python code until RestoreThread
> dbus_pending_call_block(self.pending_call)
> + PyEval_RestoreThread(_save)
>
> def set_notify(self, reply_handler, error_handler):
> user_data = (reply_handler, error_handler)
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
--
More information about the dbus
mailing list