summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorTony Roberts <tony@pyxll.com>2019-02-02 17:16:42 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2019-02-02 17:16:42 (GMT)
commit4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f (patch)
tree18e9232f27d8bee1c9a8139937b69ec013a19abf /Python/sysmodule.c
parent2de576e16d42ce43698d384d0dd46ba6cf165424 (diff)
downloadcpython-4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f.zip
cpython-4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f.tar.gz
cpython-4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f.tar.bz2
bpo-33895: Relase GIL while calling functions that acquire Windows loader lock (GH-7789)
LoadLibrary, GetProcAddress, FreeLibrary and GetModuleHandle acquire the system loader lock. Calling these while holding the GIL will cause a deadlock on the rare occasion that another thread is detaching and needs to destroy its thread state at the same time.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index f1cd74e..c7e68aa 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1159,7 +1159,9 @@ sys_getwindowsversion_impl(PyObject *module)
// We need to read the version info from a system file resource
// to accurately identify the OS version. If we fail for any reason,
// just return whatever GetVersion said.
+ Py_BEGIN_ALLOW_THREADS
hKernel32 = GetModuleHandleW(L"kernel32.dll");
+ Py_END_ALLOW_THREADS
if (hKernel32 && GetModuleFileNameW(hKernel32, kernel32_path, MAX_PATH) &&
(verblock_size = GetFileVersionInfoSizeW(kernel32_path, NULL)) &&
(verblock = PyMem_RawMalloc(verblock_size))) {