summaryrefslogtreecommitdiffstats
path: root/src/if_python.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-02-13 14:17:08 +0100
committerBram Moolenaar <Bram@vim.org>2013-02-13 14:17:08 +0100
commit76d711c3b5397b749a67d229150d3c1ff3f33add (patch)
treeca5c0745ab1f3995faacee77be1bf4369ae4765d /src/if_python.c
parent51971b33988e590901b9f6ad14a5a36f276afd0b (diff)
updated for version 7.3.808v7.3.808
Problem: Python threads still do not work properly. Solution: Fix both Python 2 and 3. Add tests. (Ken Takata)
Diffstat (limited to 'src/if_python.c')
-rw-r--r--src/if_python.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/if_python.c b/src/if_python.c
index 1bf737fc4c..d0314e2f53 100644
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -741,7 +741,7 @@ Python_Init(void)
PyMac_Initialize();
#endif
/* Initialise threads, and below save the state using
- * PyGILState_Ensure. Without the call to PyGILState_Ensure, thread
+ * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread
* specific state (such as the system trace hook), will be lost
* between invocations of Python code. */
PyEval_InitThreads();
@@ -755,10 +755,6 @@ Python_Init(void)
if (PythonMod_Init())
goto fail;
- /* The first python thread is vim's, release the lock. */
- Python_SaveThread();
- pygilstate = PyGILState_Ensure();
-
globals = PyModule_GetDict(PyImport_AddModule("__main__"));
/* Remove the element from sys.path that was added because of our
@@ -767,7 +763,14 @@ Python_Init(void)
* the current directory in sys.path. */
PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");
- PyGILState_Release(pygilstate);
+ /* lock is created and acquired in PyEval_InitThreads() and thread
+ * state is created in Py_Initialize()
+ * there _PyGILState_NoteThreadState() also sets gilcounter to 1
+ * (python must have threads enabled!)
+ * so the following does both: unlock GIL and save thread state in TLS
+ * without deleting thread state
+ */
+ PyEval_SaveThread();
initialised = 1;
}