Fixed ticket #93: Python readline() blocks/hang because C module running on different thread is calling a blocking OS call
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@945 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip-apps/src/py_pjsua/py_pjsua.c b/pjsip-apps/src/py_pjsua/py_pjsua.c
index cb370f1..e5cb6ca 100644
--- a/pjsip-apps/src/py_pjsua/py_pjsua.c
+++ b/pjsip-apps/src/py_pjsua/py_pjsua.c
@@ -2163,7 +2163,15 @@
{
return NULL;
}
+
+ /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
+ * construct, or otherwise many Python blocking functions (such as
+ * time.sleep(), readline(), etc.) may hang/block indefinitely.
+ * See http://www.python.org/doc/current/api/threads.html for more info.
+ */
+ Py_BEGIN_ALLOW_THREADS
ret = pjsua_handle_events(msec);
+ Py_END_ALLOW_THREADS
return Py_BuildValue("i",ret);
}