I want to stop the execution of some complex function after it runs for 30 seconds. I find some references saying I should use thread, but ppl also mention a thread shouldn't be terminated in any cases.
If the function may take hours but must be cancelled after some time, and modifying it is not an option, a safe alternative is to move it to a different process and killing the process after the specified time has elapsed without any results.