Message395947
> [Windows] _thread.start_new_thread() should close the thread handle
So far, I'm not convinced that Python must be changed.
I modified my Python locally so thread_run() writes GetCurrentThread() to stderr.
Example:
---
SLEEP = 5
import ctypes
import _thread
import time
import os
HANDLE = ctypes.c_voidp
DWORD = ctypes.c_ulong
ResumeThread = ctypes.windll.kernel32.ResumeThread
ResumeThread.argtypes = (HANDLE,)
ResumeThread.restype = DWORD
SuspendThread = ctypes.windll.kernel32.SuspendThread
SuspendThread.argtypes = (HANDLE,)
SuspendThread.restype = DWORD
def func():
time.sleep(SLEEP)
print("--thread exit--")
def check_handle(handle):
x = SuspendThread(handle)
print(f"SuspendThread({handle}) -> {x}")
x = ResumeThread(handle)
print(f"ResumeThread({handle}) -> {x}")
handle = _thread.start_new_thread(func, ())
print(f"start_new_thread() -> {handle}")
check_handle(handle)
time.sleep(SLEEP+1)
check_handle(handle)
---
Output:
---
start_new_thread() -> 2436
SuspendThread(2436) -> 4294967295
ResumeThread(2436) -> 4294967295
thread_run: GetCurrentThread() -> -2
--thread exit--
SuspendThread(2436) -> 4294967295
ResumeThread(2436) -> 4294967295
---
It seems like the handle returned by _beginthreadex() cannot be used with SuspendThread() or ResumeThread(): both fail. GetHandleInformation() also fails on this handle (I tried os.get_handle_inheritable()). |
|
Date |
User |
Action |
Args |
2021-06-16 16:01:21 | vstinner | set | recipients:
+ vstinner, paul.moore, tim.golden, zach.ware, eryksun, steve.dower |
2021-06-16 16:01:21 | vstinner | set | messageid: <1623859281.05.0.668102747164.issue44436@roundup.psfhosted.org> |
2021-06-16 16:01:21 | vstinner | link | issue44436 messages |
2021-06-16 16:01:20 | vstinner | create | |
|