Killing a thread

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bugdot

So, I have a thread which runs youtube-dl and uses it to search for a song and download it.

So, I have this problem where if the user types a query, I need to kill the existing thread and then start the new one.

This the code I use to run my thread function.

search_thread = Thread.new()
var search_err = search_thread.start(self, "print_search", [$UISearch/LineEdit.text])
print_search($UISearch/LineEdit.text)

Now I some how need to know if one instance of search_thread(search_err?) is running and if it is kill it and start a new one.