Python Terminated Thread Cannot Reboot

I have a thread that executes when some action happens. Given the logic of the program, a thread cannot be started while another instance of it is still running. However, when I call it a second time, I get the error message "RuntimeError: thread already started". I added a check to make sure she is really alive using the Thread.is_alive () function, and she is actually dead.

What am I doing wrong?

I can provide more detailed information as needed.

+6
python multithreading runtime-error
source share
3 answers

Threads cannot be restarted. You must re-create the Thread in order to start it again.

+11
source share

From Python, the documentation: start() starts thread activity. This must be called no more than once for a stream object. It orders the run() method of the object to be called in a separate control flow.

If you derived the class from threading.Thread, you can add Thread.__init__(self) at the end of your start method, and you can call the start again and it will automatically re-initialize when it is done.

+6
source share

You can try to install

 thread._Thread__started = False 

This is not officially documented, so use it at your own risk! :)

+2
source share

All Articles