I founded a nice package that is called kthread which simplify the threading in python. I have also found out that it is possible to name give a thread by its name etc:
import sys
import time
import kthread
def func():
try:
while True:
time.sleep(0.2)
finally:
sys.stdout.write("Greetings from Vice City!\n")
sys.stdout.flush()
t = kthread.KThread(target=func, name="KillableThread1")
t.start()
t.is_alive()
t.terminate()
t.is_alive()
Instead of doing t.terminate() I wonder if there is a possibility to remove a thread by given name?
name
of the thread and the value the reference to the threadt
. Then you can also remove it when the thread is terminate.Threading.Thread
class by adding methods liketerminate
to it. When you callterminate
it raises an exception to kill the thread. I think this stackoverflow.com/questions/323972/… and this oreilly.com/library/view/python-cookbook/0596001673/… may help.