* python/dbus_bindings.pyx.in (cunregister_function_handler,
authorJohn (J5) Palmieri <johnp@redhat.com>
Tue, 28 Jun 2005 19:36:51 +0000 (19:36 +0000)
committerJohn (J5) Palmieri <johnp@redhat.com>
Tue, 28 Jun 2005 19:36:51 +0000 (19:36 +0000)
  cmessage_function_handler): Patch from
  Anthony Baxter <anthony@interlink.com.au> fixes threading problems
  by using the Py_GILState_Ensure/Release to synchronize with the
  python runtime.

ChangeLog
python/dbus_bindings.pyx.in

index 7445f9298925adad2c9edaef31c57412f6386789..48ddf6b34515dc900c15065b2d015592bee98ff7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-06-28  John (J5) Palmieri  <johnp@redhat.com>
+
+       * python/dbus_bindings.pyx.in (cunregister_function_handler,
+       cmessage_function_handler): Patch from 
+       Anthony Baxter <anthony@interlink.com.au> fixes threading problems
+       by using the Py_GILState_Ensure/Release to synchronize with the
+       python runtime.
+       
 2005-06-28  Ray Strode  <rstrode@redhat.com>
 
        *  dbus/dbus-spawn.c (_dbus_babysitter_unref): kill
index 3c819934868b5212c5fe7623fa0ea77625775fc7..34341c4a6125b638df6a0baf48663774236f2c4c 100644 (file)
@@ -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 = <object>user_data
-    assert (type(tup) == list)    
-    function = tup[1]
-    conn = Connection()
-    conn.__cinit__(None, connection)
+    cdef PyGILState_STATE gil
+
+    gil = PyGILState_Ensure()
+    try:
+        itup = <object>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 = <object>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 = <object>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