STINNER Victor <[email protected]> added the comment:
> [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()).
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue44436>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com