Reputation: 339
I have a simple call to a thread:
aThread = threading.Thread(target=singleDriverThread, args=(d[0]))
and then I start it (aThread.start)
when I need to stop the thread I do:
aThread.join()
but the thread keep running.. Help?
Upvotes: 1
Views: 224
Reputation: 6771
If you want to stop a thread, you should either kill or signal the thread. This SO answer and this SO answer deal with stopping the thread. The join
method only waits for the thread to exit.
In general, to make a thread stop gracefully, it is useful to have a communication channel with it so that a stop message / signal can be passed.
Upvotes: 1
Reputation: 265
The thread will continue to run until the callable singleDriverThread
returns.
Example:
If your callable singleDriverThread
looks like this the code will never stop:
def singleDriverThread():
while True:
# do stuff in eternal loop
pass
But if singleDriverThread
instead looks like this:
def singleDriverThread():
# do stuff
return
then the callable will return and the thread will join with the rest of your code.
Upvotes: 1