comparison src/if_python3.c @ 4109:3b2a771abb39 v7.3.808

updated for version 7.3.808 Problem: Python threads still do not work properly. Solution: Fix both Python 2 and 3. Add tests. (Ken Takata)
author Bram Moolenaar <bram@vim.org>
date Wed, 13 Feb 2013 14:17:08 +0100
parents 778ff2e87806
children 6b1f3fc893cd
comparison
equal deleted inserted replaced
4108:be70761a9a89 4109:3b2a771abb39
727 #if !defined(MACOS) || defined(MACOS_X_UNIX) 727 #if !defined(MACOS) || defined(MACOS_X_UNIX)
728 Py_Initialize(); 728 Py_Initialize();
729 #else 729 #else
730 PyMac_Initialize(); 730 PyMac_Initialize();
731 #endif 731 #endif
732 /* Initialise threads, and save the state using PyGILState_Ensure. 732 /* Initialise threads, and below save the state using
733 * Without the call to PyGILState_Ensure, thread specific state (such 733 * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread
734 * as the system trace hook), will be lost between invocations of 734 * specific state (such as the system trace hook), will be lost
735 * Python code. */ 735 * between invocations of Python code. */
736 PyEval_InitThreads(); 736 PyEval_InitThreads();
737 pygilstate = PyGILState_Ensure();
738
739 #ifdef DYNAMIC_PYTHON3 737 #ifdef DYNAMIC_PYTHON3
740 get_py3_exceptions(); 738 get_py3_exceptions();
741 #endif 739 #endif
742 740
743 if (PythonIO_Init()) 741 if (PythonIO_Init())
752 * Only after vim has been imported, the element does exist in 750 * Only after vim has been imported, the element does exist in
753 * sys.path. 751 * sys.path.
754 */ 752 */
755 PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); 753 PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))");
756 754
757 // lock is created and acquired in PyEval_InitThreads() and thread 755 /* lock is created and acquired in PyEval_InitThreads() and thread
758 // state is created in Py_Initialize() 756 * state is created in Py_Initialize()
759 // there _PyGILState_NoteThreadState() also sets gilcounter to 1 757 * there _PyGILState_NoteThreadState() also sets gilcounter to 1
760 // (python must have threads enabled!) 758 * (python must have threads enabled!)
761 // so the following does both: unlock GIL and save thread state in TLS 759 * so the following does both: unlock GIL and save thread state in TLS
762 // without deleting thread state 760 * without deleting thread state
763 PyGILState_Release(pygilstate); 761 */
762 PyEval_SaveThread();
764 763
765 py3initialised = 1; 764 py3initialised = 1;
766 } 765 }
767 766
768 return 0; 767 return 0;