Changeset: 1cc216b415ef for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1cc216b415ef
Modified Files:
        monetdb5/extras/pyapi/pyapi.c
Branch: pyapi
Log Message:

To support multiple clients calling Python code at once (i.e. interquery 
parallelism) when a second client would normally start waiting for the lock we 
fork the process instead.


diffs (48 lines):

diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -88,6 +88,7 @@ int PyAPIEnabled(void) {
 static MT_Lock pyapiLock;
 static int pyapiInitialized = FALSE;
 
+static bool python_call_active = false;
 
 static PyObject **dictionaries = NULL;
 static Client *clients = NULL;
@@ -423,6 +424,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
     PyGILState_STATE gstate = PyGILState_LOCKED;
     bit varres = sqlfun ? sqlfun->varres : 0;
     int retcols = !varres ? pci->retc : -1;
+    bool holds_gil = !mapped;
 
     (void) cntxt;
 
@@ -526,6 +528,15 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
             inp->bat = b;
         }
     }
+    if (!mapped) {
+        MT_lock_set(&pyapiLock, "pyapi.evaluate");
+        if (python_call_active) {
+            mapped = true;
+            holds_gil = false;
+        }
+        else python_call_active = true;
+        MT_lock_unset(&pyapiLock, "pyapi.evaluate");
+    }
 
     /*[FORK_PROCESS]*/
     if (mapped)
@@ -1056,6 +1067,12 @@ returnvalues:
 
     VERBOSE_MESSAGE("Cleaning up.\n");
 
+    if (holds_gil){
+        MT_lock_set(&pyapiLock, "pyapi.evaluate");
+        python_call_active = false;
+        MT_lock_unset(&pyapiLock, "pyapi.evaluate");
+    }
+
     // Actual cleanup
     // Cleanup input BATs
     for (i = pci->retc + 2; i < pci->argc; i++)
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to