Unfortunately, unable to interrupt threads. The only way a thread ends is to let her code run to the end. What you can do, if your thread has a loop, is establish a communication channel with the thread, using a mechanism like Queue
s, and make your thread check that channel within the loop. Then your main program can use the channel to send a message to the thread, which, when checking the channel, will see that it should stop the loop and close.
In other words, you have to write code to ask the thread to commit suicide, and if she’s listening, she’ll do it.
I suggest avoiding the use of threads, in python there are almost no advantages in using threads because of GIL. Use asynchronous programming, so you can control the timing of the context change and therefore make parallel structures more cancellable. See for example this article (in English):
https://vorpus.org/blog/timeouts-and-cancellation-for-humans/
When you say interrupt refers to finishing your
execução
ordeletá-la
?– ThiagoO
Delete it, but either finish its execution, whatever rsrs, as long as it is no longer active...
– Adrien