Skip to content
Advertisement

How can I kill a thread with python

I am making a random number guessing game with GUI (Tkinter) and this comes up RuntimeError: threads can only be started once. I’m trying to kill the thread but I can’t find any way. Here’s the code:

JavaScript

In the first function (main) is where I call the Thread and in the second function (process) is where I want to kill the Thread.

Advertisement

Answer

The error is trying to tell you that passing command=t1.start will result in calling start() on the same t1 instance every time the button is pressed. In Python, you cannot call thread.start() multiple times on the same thread instance. Change the following lines:

JavaScript

To

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement