- pModule = PyImport_Import(pName);
- Py_DECREF(pName); /* release pName */
-
- if (pModule != NULL) {
- pDict = PyModule_GetDict(pModule);
- /* pDict is a borrowed reference */
-
- pFunc = PyDict_GetItemString(pDict, (char *)event);
- /* pFun: Borrowed reference */
-
- if (pFunc && PyCallable_Check(pFunc)) {
- /* Create JCR argument to send to function */
- pArgs = PyTuple_New(1);
- pJCR = (PyObject *)PyObject_New(JCRObject, &JCRType);
- ((JCRObject *)pJCR)->jcr = jcr;
- if (!pJCR) {
- Py_DECREF(pArgs);
- Py_DECREF(pModule);
- Jmsg0(jcr, M_ERROR, 0, "Could not create JCR Python Object.\n");
- return -1;
- }
- Py_INCREF(pJCR);
- /* pJCR reference stolen here: */
- PyTuple_SetItem(pArgs, 0, pJCR);
-
- /* Finally, we call the module here */
- bstrncpy(jcr->event, event, sizeof(jcr->event));
- pCall = PyObject_CallObject(pFunc, pArgs);
- jcr->event[0] = 0; /* no event in progress */
- Py_DECREF(pArgs);
- Py_DECREF(pJCR);
- if (pCall != NULL) {
- Py_DECREF(pCall);
- } else {
- Py_DECREF(pModule);
- PyErr_Print();
- Jmsg1(jcr, M_ERROR, 0, "Error running Python module: %s\n", event);
- return 0; /* error running function */
- }
- /* pDict and pFunc are borrowed and must not be Py_DECREF-ed */
- } else {
- if (PyErr_Occurred()) {
- PyErr_Print();
- Dmsg1(000, "Python event %s function not callable.\n", event);
- }
- Jmsg1(jcr, M_ERROR, 0, "Python function \"%s\" not found in module.\n", event);
- return -1; /* function not found */
- }
- Py_DECREF(pModule);
- } else {
- return 0; /* Module not present */
+}
+
+static void term_python_lock()
+{
+ rwl_destroy(&python_rwlock);
+}
+
+/* This applies to a drive and to Volumes */
+void lock_python()
+{
+ int errstat;
+ if ((errstat=rwl_writelock(&python_rwlock)) != 0) {
+ berrno be;
+ Emsg2(M_ABORT, 0, "Python rwl_writelock failure. stat=%d: ERR=%s\n",
+ errstat, be.bstrerror(errstat));
+ }
+}
+
+void unlock_python()
+{
+ int errstat;
+ if ((errstat=rwl_writeunlock(&python_rwlock)) != 0) {
+ berrno be;
+ Emsg2(M_ABORT, 0, "Python rwl_writeunlock failure. stat=%d: ERR=%s\n",
+ errstat, be.bstrerror(errstat));