From a3406a82793298943c02f4b4088a9ef5b35f0279 Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Tue, 28 Jun 2005 19:36:51 +0000 Subject: * python/dbus_bindings.pyx.in (cunregister_function_handler, cmessage_function_handler): Patch from Anthony Baxter fixes threading problems by using the Py_GILState_Ensure/Release to synchronize with the python runtime. --- python/dbus_bindings.pyx.in | 60 +++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'python') diff --git a/python/dbus_bindings.pyx.in b/python/dbus_bindings.pyx.in index 3c819934..34341c4a 100644 --- a/python/dbus_bindings.pyx.in +++ b/python/dbus_bindings.pyx.in @@ -34,6 +34,10 @@ cdef extern from "Python.h": void Py_XINCREF (object) void Py_XDECREF (object) object PyString_FromStringAndSize(char *, int) + ctypedef void *PyGILState_STATE + void PyErr_Clear() + PyGILState_STATE PyGILState_Ensure() + void PyGILState_Release(PyGILState_STATE) ctypedef struct DBusError: char *name @@ -158,38 +162,46 @@ cdef class MessageIter cdef void cunregister_function_handler (DBusConnection *connection, void *user_data): cdef Connection conn - tup = user_data - assert (type(tup) == list) - function = tup[1] - conn = Connection() - conn.__cinit__(None, connection) + cdef PyGILState_STATE gil + + gil = PyGILState_Ensure() + try: + itup = user_data + assert (type(tup) == list) + function = tup[1] + conn = Connection() + conn.__cinit__(None, connection) - args = [conn] - function(*args) + args = [conn] + function(*args) + finally: + PyGILState_Release(gil) cdef DBusHandlerResult cmessage_function_handler (DBusConnection *connection, DBusMessage *msg, void *user_data): cdef Connection conn cdef Message message + cdef PyGILState_STATE gil - tup = user_data - assert (type(tup) == list) - function = tup[0] - message = Message(_create=0) - message._set_msg(msg) - - conn = Connection() - conn.__cinit__(None, connection) - - args = [conn, - message] - retval = function(*args) - if (retval == None): - retval = DBUS_HANDLER_RESULT_HANDLED - - return retval - + gil = PyGILState_Ensure() + try: + tup = user_data + assert (type(tup) == list) + function = tup[0] + message = Message(_create=0) + message._set_msg(msg) + conn = Connection() + conn.__cinit__(None, connection) + args = [conn, + message] + retval = function(*args) + if (retval == None): + retval = DBUS_HANDLER_RESULT_HANDLED + return retval + finally: + PyGILState_Release(gil) + cdef class Connection: cdef DBusConnection *conn -- cgit