Killing suspended functions in Python in a multithreaded environment
I want to kill a function that executes very long The important thing is that this function is in the C extension (included in Python). I hope this solution can work in a multithreaded environment Because it is wrapped in Python, this thread can save Gil
I can't control what happens in this extension (I don't think this code will respond to interrupts)
I'm pretty sure this code can only run on UNIX machines But the python kill hanging function doesn't work because I think signals don't work in a multithreaded environment (AFAIK doesn't define which thread will catch them) - but I may be wrong on this issue:) so correct me
Is there any way for me to solve this problem without generating a new process
Solution
My solution is to wrap this function in another Python process and kill it if necessary
For those searching for this problem, this is a suggestion: since the process startup time (starting the interpreter, loading the module and then loading the data into memory) may take several seconds to group function calls, this overhead will be killed soon (so there is really no reusable solution)
The sample solution is published to another problem: how to interrupt native extension code without killing the interpreter