You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2018/12/24 15:53:25 UTC

[GitHub] ifplusor commented on a change in pull request #20: Fixed deadlock, and add args field for python callback.

ifplusor commented on a change in pull request #20: Fixed deadlock, and add args field for python callback.
URL: https://github.com/apache/rocketmq-client-python/pull/20#discussion_r243841340
 
 

 ##########
 File path: src/PythonWrapper.cpp
 ##########
 @@ -30,24 +31,37 @@ using namespace std;
 const char *VERSION =
         "PYTHON_CLIENT_VERSION: " PYTHON_CLIENT_VERSION ", BUILD DATE: " PYCLI_BUILD_DATE " ";
 
-map<CPushConsumer *, PyObject *> g_CallBackMap;
+map<CPushConsumer *, pair<PyObject *, object>> g_CallBackMap;
 
 class PyThreadStateLock {
 public:
-    PyThreadStateLock(void) {
+    PyThreadStateLock() {
         state = PyGILState_Ensure();
     }
 
-    ~PyThreadStateLock(void) {
-        if (state == PyGILState_LOCKED) {
-            PyGILState_Release(state);
-        }
+    ~PyThreadStateLock() {
+        // NOTE: 必须跟 PyGILState_Ensure 成对出现,否则可能出现死锁!!!
+        PyGILState_Release(state);
 
 Review comment:
   the condition statement cause deadlock in my code. so i remove it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services