-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed as not planned
Labels
type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
If we need to kill one thread from another we can use standard python trick:
def raise_in_thread(tid, exctype):
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(
ctypes.c_long(tid),
ctypes.py_object(exctype)
)
if res == 0:
raise ValueError("Invalid thread ID")
elif res > 1:
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), None)
raise SystemError("PyThreadState_SetAsyncExc failed")
but if thread stuck in blocking call it raise exception only after blocking call returs. So we need interrupt blocking call inside thread.
I created safe hack solution that exploits signals but it works only with custom input functions. To make the solution universal (compatible with CPython’s read() function) , for example, we need to force CPython’s PyErr_CheckSignals() somehow to return True.
Is there standard methods to do that?
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/how-to-kill-thread-in-python-which-stuck-in-blocking-call/102431
Metadata
Metadata
Assignees
Labels
type-featureA feature request or enhancementA feature request or enhancement