Mercurial > vim
comparison src/if_python3.c @ 22572:0fd4d7548b07 v8.2.1834
patch 8.2.1834: PyEval_InitThreads() is deprecated in Python 3.9
Commit: https://github.com/vim/vim/commit/efc0d94afc48a03b07955e91315e7e67945cd079
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 11 18:05:02 2020 +0200
patch 8.2.1834: PyEval_InitThreads() is deprecated in Python 3.9
Problem: PyEval_InitThreads() is deprecated in Python 3.9.
Solution: Do not call PyEval_InitThreads in Python 3.9 and later. (Ken
Takata, closes #7113) Avoid warnings for functions.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 11 Oct 2020 18:15:04 +0200 |
parents | 48454576b23c |
children | 3ceb24835183 |
comparison
equal
deleted
inserted
replaced
22571:7fb99507041c | 22572:0fd4d7548b07 |
---|---|
1000 PyImport_AppendInittab("vim", Py3Init_vim); | 1000 PyImport_AppendInittab("vim", Py3Init_vim); |
1001 | 1001 |
1002 reset_stdin(); | 1002 reset_stdin(); |
1003 Py_Initialize(); | 1003 Py_Initialize(); |
1004 | 1004 |
1005 // Initialise threads, and below save the state using | 1005 #if PY_VERSION_HEX < 0x03090000 |
1006 // PyEval_SaveThread. Without the call to PyEval_SaveThread, thread | 1006 // Initialise threads. This is deprecated since Python 3.9. |
1007 // specific state (such as the system trace hook), will be lost | |
1008 // between invocations of Python code. | |
1009 PyEval_InitThreads(); | 1007 PyEval_InitThreads(); |
1008 #endif | |
1010 #ifdef DYNAMIC_PYTHON3 | 1009 #ifdef DYNAMIC_PYTHON3 |
1011 get_py3_exceptions(); | 1010 get_py3_exceptions(); |
1012 #endif | 1011 #endif |
1013 | 1012 |
1014 if (PythonIO_Init_io()) | 1013 if (PythonIO_Init_io()) |
1022 // the current directory in sys.path. | 1021 // the current directory in sys.path. |
1023 // Only after vim has been imported, the element does exist in | 1022 // Only after vim has been imported, the element does exist in |
1024 // sys.path. | 1023 // sys.path. |
1025 PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); | 1024 PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); |
1026 | 1025 |
1027 // lock is created and acquired in PyEval_InitThreads() and thread | 1026 // Without the call to PyEval_SaveThread, thread specific state (such |
1028 // state is created in Py_Initialize() | 1027 // as the system trace hook), will be lost between invocations of |
1029 // there _PyGILState_NoteThreadState() also sets gilcounter to 1 | 1028 // Python code. |
1030 // (python must have threads enabled!) | 1029 // GIL may have been created and acquired in PyEval_InitThreads() and |
1031 // so the following does both: unlock GIL and save thread state in TLS | 1030 // thread state is created in Py_Initialize(); there |
1032 // without deleting thread state | 1031 // _PyGILState_NoteThreadState() also sets gilcounter to 1 (python must |
1032 // have threads enabled!), so the following does both: unlock GIL and | |
1033 // save thread state in TLS without deleting thread state | |
1033 PyEval_SaveThread(); | 1034 PyEval_SaveThread(); |
1034 | 1035 |
1035 py3initialised = 1; | 1036 py3initialised = 1; |
1036 } | 1037 } |
1037 | 1038 |