I’m trying to implement some basic threading in my script and I need to check whether the thread already exist or not, I’ve found how to set names but cannot figure out how to use is_alive function by name
class History(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
#do some stuff
for i in range(10):
t = History
t.setName("name%s"%i))
t().start()
how can I check later is thread name5 is alive or not?
The
is_alivemethod does not take any arguments. You don’t useis_aliveby name. Instead, just callt.is_alive()to check if the thread
tis alive.PS. The docs say the name attribute,
so don’t rely on the name as a definitive means of identification.