[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Weechat-cvs] weechat/src/plugins/scripts/python weechat-pyth...
From: |
kolter |
Subject: |
[Weechat-cvs] weechat/src/plugins/scripts/python weechat-pyth... |
Date: |
Thu, 15 Jun 2006 22:24:12 +0000 |
CVSROOT: /sources/weechat
Module name: weechat
Changes by: kolter <kolter> 06/06/15 22:24:12
Modified files:
src/plugins/scripts/python: weechat-python.c
Log message:
improve python sub-interpreters management
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/weechat/src/plugins/scripts/python/weechat-python.c?cvsroot=weechat&r1=1.37&r2=1.38
Patches:
Index: weechat-python.c
===================================================================
RCS file: /sources/weechat/weechat/src/plugins/scripts/python/weechat-python.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- weechat-python.c 10 Jun 2006 21:34:16 -0000 1.37
+++ weechat-python.c 15 Jun 2006 22:24:12 -0000 1.38
@@ -52,13 +52,15 @@
t_plugin_script *script,
char *function, char *arg1, char *arg2, char *arg3)
{
+ PyThreadState *old_state;
PyObject *evMain;
PyObject *evDict;
PyObject *evFunc;
PyObject *rc;
int ret;
- PyThreadState_Swap (script->interpreter);
+ PyEval_AcquireLock ();
+ old_state = PyThreadState_Swap (script->interpreter);
evMain = PyImport_AddModule ((char *) "__main__");
evDict = PyModule_GetDict (evMain);
@@ -69,6 +71,10 @@
plugin->print_server (plugin,
"Python error: unable to run function \"%s\"",
function);
+
+ PyThreadState_Swap (old_state);
+ PyEval_ReleaseLock ();
+
return PLUGIN_RC_KO;
}
@@ -95,6 +101,10 @@
if (rc == Py_None)
{
python_plugin->print_server (python_plugin, "Python error: function
\"%s\" must return a valid value", function);
+
+ PyThreadState_Swap (old_state);
+ PyEval_ReleaseLock ();
+
return PLUGIN_RC_OK;
}
@@ -107,8 +117,11 @@
if (PyErr_Occurred ()) PyErr_Print ();
if (ret < 0)
- return PLUGIN_RC_OK;
- else
+ ret = PLUGIN_RC_OK;
+
+ PyThreadState_Swap (old_state);
+ PyEval_ReleaseLock ();
+
return ret;
}
@@ -1368,7 +1381,7 @@
{
char *argv[] = { "__weechat_plugin__" , NULL };
FILE *fp;
- PyThreadState *python_current_interpreter;
+ PyThreadState *python_current_interpreter, *old_state;
PyObject *weechat_module, *weechat_outputs, *weechat_dict;
plugin->print_server (plugin, "Loading Python script \"%s\"", filename);
@@ -1383,6 +1396,7 @@
python_current_script = NULL;
+ PyEval_AcquireLock ();
python_current_interpreter = Py_NewInterpreter ();
PySys_SetArgv(1, argv);
@@ -1391,10 +1405,13 @@
plugin->print_server (plugin,
"Python error: unable to create new
sub-interpreter");
fclose (fp);
+
+ PyEval_ReleaseLock ();
+
return 0;
}
- PyThreadState_Swap (python_current_interpreter);
+ old_state = PyThreadState_Swap (python_current_interpreter);
weechat_module = Py_InitModule ("weechat", weechat_python_funcs);
@@ -1402,8 +1419,12 @@
{
plugin->print_server (plugin,
"Python error: unable to initialize WeeChat
module");
- Py_EndInterpreter (python_current_interpreter);
fclose (fp);
+
+ Py_EndInterpreter (python_current_interpreter);
+ PyThreadState_Swap (old_state);
+ PyEval_ReleaseLock ();
+
return 0;
}
@@ -1439,8 +1460,12 @@
"Python error: unable to parse file \"%s\"",
filename);
free (python_current_script_filename);
- Py_EndInterpreter (python_current_interpreter);
fclose (fp);
+
+ Py_EndInterpreter (python_current_interpreter);
+ PyThreadState_Swap (old_state);
+ PyEval_ReleaseLock ();
+
/* if script was registered, removing from list */
if (python_current_script != NULL)
weechat_script_remove (plugin, &python_scripts,
python_current_script);
@@ -1459,12 +1484,19 @@
"Python error: function \"register\" not found "
"in file \"%s\"",
filename);
+
Py_EndInterpreter (python_current_interpreter);
+ PyThreadState_Swap (old_state);
+ PyEval_ReleaseLock ();
+
return 0;
}
python_current_script->interpreter = (PyThreadState *)
python_current_interpreter;
+ PyThreadState_Swap (old_state);
+ PyEval_ReleaseLock ();
+
return 1;
}
@@ -1718,8 +1750,8 @@
}
PyEval_InitThreads();
-
- python_mainThreadState = PyThreadState_Get();
+ python_mainThreadState = PyThreadState_Swap(NULL);
+ PyEval_ReleaseLock ();
if (python_mainThreadState == NULL)
{
@@ -1758,7 +1790,9 @@
/* free Python interpreter */
if (python_mainThreadState != NULL)
{
+ PyEval_AcquireLock ();
PyThreadState_Swap (python_mainThreadState);
+ PyEval_ReleaseLock ();
python_mainThreadState = NULL;
}
- [Weechat-cvs] weechat/src/plugins/scripts/python weechat-pyth...,
kolter <=