# player is a class object (class Game)
def the_hunt(target_number, player):
timer_thread = Thread(target=timer, args=(player, ))
timer_thread.start()
while True:
# when time is zero sec it will terminate the game
if not timer_thread.is_alive():
print("The Hunt is Over. You ran out of time!")
player.game_status(False)
return False
# check for the win
if player._score == player.win_points:
timer_thread.cancel()
player.game_status(True)
def timer(obj: Game):
sleep_duration = 60
while sleep_duration > 0:
time.sleep(1)
obj.duration_reduce(1)
sleep_duration -= 1
error I get AttributeError: 'Thread' object has no attribute 'cancel' when I used timer_thread = Thread(target=timer) instead of timer_thread = Thread(target=timer, args=(player, )) and def timer(): it worked but with the given code where I have used class object, it gives an error. I am not using threading in class just passing a value to the class