Based on my testing, this is because threads can only be started once, and as the timer relies on a thread, the timer can only be started once. This means that the only way to re-start the timer would be to do:

def newTimer():
    global t
    t = Timer(10.0,api_call)
newTimer()

instead of the t = Timer part, and do

t.cancel()
newTimer()
t.start()

instead of the current re-start code.

This makes your full code:

from threading import Timer

def api_call():
    print("Call that there api")

def newTimer():
    global t
    t = Timer(10.0,api_call)
newTimer()


def my_callback(channel):

    if something_true:
        print('reset timer and start again')
        t.cancel()
        newTimer()
        t.start()
        print("\n timer started")
    elif something_else_true:
        t.cancel()
        print("timer canceled")
    else:
       t.cancel()
       print('cancel timer for sure')

try:
    if outside_input_that_can_happen_a_lot:
        my_callback()

finally:
    #cleanup objects

Hope this helps.

Answer from CrazySqueak on Stack Overflow
🌐
GitHub
gist.github.com › aeroaks › ac4dbed9c184607a330c
Reset Timer in Python · GitHub
Reset Timer in Python. GitHub Gist: instantly share code, notes, and snippets.
Discussions

Timer cannot restart after it is being stopped in Python - Stack Overflow
I am using Python 2.7. I have a timer that keeps repeating a timer callback action until it has been stopped. It uses a Timer object. The problem is that after it has been stopped, it cannot be res... More on stackoverflow.com
🌐 stackoverflow.com
June 6, 2014
Python: Run code every n seconds and restart timer on condition - Stack Overflow
This may be simpler than I think but I'd like to create timer that, upon reaching a limit (say 15 mins), some code is executed. Meanwhile every second, I'd like to test for a condition. If the More on stackoverflow.com
🌐 stackoverflow.com
How do I stop a function and restart it when it is called again?
You can make a generator function that yields a result, and you call next every time you want the next iteration. These are functions that are designed to continue where you left off each time you ask for the next iteration. https://realpython.com/introduction-to-python-generators/ mini-example from that article: def multi_yield(): yield_str = "This will print the first string" yield yield_str yield_str = "This will print the second string" yield yield_str multi_obj = multi_yield() print(next(multi_obj)) #This will print the first string print(next(multi_obj)) #This will print the second string print(next(multi_obj)) # raises the StopIteration exception More on reddit.com
🌐 r/learnpython
3
7
August 18, 2021
Created My First Tkinter Project: Count-Down Timer : Reset/pause and resume buttons.
pause = "No" an option is to use paused = False which is more pythonic. Glad you are having fun More on reddit.com
🌐 r/learnpython
10
52
March 20, 2023
🌐
PyPI
pypi.org › project › resettabletimer
Client Challenge
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Python
mail.python.org › pipermail › tutor › 2012-November › 092767.html
[Tutor] Reusing Timers (threading.timer)
November 14, 2012 - Changing the timer is not supported. I expect that calling my_timer.start() after cancelling it would restart it, but haven't tested it. Just because you create a new timer doesn't mean you have to give it an entirely new name. > 3. If I get a value from a textbox, how do I parse it from the string > value to an integer (or float)?
🌐
Real Python
realpython.com › python-timer
Python Timer Functions: Three Ways to Monitor Your Code – Real Python
December 8, 2024 - On the other hand, when you call .stop(), you first check that the Python timer is running. If it is, then you calculate the elapsed time as the difference between the current value of perf_counter() and the one that you stored in ._start_time. Finally, you reset ._start_time so that the timer can be restarted, and print the elapsed time.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › how do i stop a function and restart it when it is called again?
r/learnpython on Reddit: How do I stop a function and restart it when it is called again?
August 18, 2021 -

I've searched around the internet and I can't seem to find an answer. I have a series of checkboxes that when clicked, calls a function that is a countdown timer. If I wait for the timer to end, and click another checkbox, it works fine. But if I check a second box while the other is still running, it starts another timer so then I have 2 timers running... or 3 or 4 depending on how many checkboxes I click. If I click another checkbox while the timer is still running, how do I get it to stop the first timer and start over?

def countdown(count):
	import beepy
	label['text'] = count 
	if count >= 0:
		root.after(1000, countdown, count - 1)
	else:
		beepy.beep(4)
		label['text'] = 0

each checkbox has this code to call the countdown function:

ttk.Checkbutton(routine, command=lambda: countdown(45))
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
A resetable background timer? - Raspberry Pi Forums
My current task is to switch an output pin using an input pin. The plan is easy: after 23 seconds of inactivity, the output goes low. If a button is pressed during that time, the timer gets reset. If that button is pressed after the the output is already low, the output is pulled high and the ...
🌐
YouTube
youtube.com › the python oracle
Python timer start and reset - YouTube
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn--Music by Eric Matyashttps://www.soundimage.orgTrack title: Darkness...
Published   January 2, 2023
Views   322
🌐
Reddit
reddit.com › r/learnpython › created my first tkinter project: count-down timer : reset/pause and resume buttons.
r/learnpython on Reddit: Created My First Tkinter Project: Count-Down Timer : Reset/pause and resume buttons.
March 20, 2023 -

Been learning functions and how to add them to buttons and working with time in general. So wanted to create a little project that will test me on those areas.

import tkinter as tk
from tkinter import *
import time


root = Tk()
root.title('                                      COUNT-DOWN TIMER')
#root.geometry("800x400")
root['background']='#2F4F4F'

total_time = 0

rest = 0

pause = "No"

#####ADD/MINUS/RESET FUNCTIONS

def add_time_hour():
    global total_time
    total_time += 3600
    countdown_label.config(text=f"{total_time//3600:02}:{(total_time//60)%60:02}:{total_time%60:02}",fg = '#00FF00',font=("Arial", 24))

def add_time_min():
    global total_time
    total_time += 60
    countdown_label.config(text=f"{total_time//3600:02}:{(total_time//60)%60:02}:{total_time%60:02}",fg= "#00FF00",font=("Arial", 24))

def add_time_sec():
    global total_time
    total_time += 1
    countdown_label.config(text=f"{total_time//3600:02}:{(total_time//60)%60:02}:{total_time%60:02}",fg= "#00FF00",font=("Arial", 24))

def add_rest_min():
    global rest
    rest += 60
    rest_label.config(text=f"{(rest // 3600) % 3600:02}:{(rest // 60) % 60:02}:{rest % 60:02}",fg= "#00FF00",font=("Arial", 24))

def reset():
    global total_time, rest,pause
    pause = "No"
    total_time = 0
    rest = 0
    countdown_label.config(text=f"{total_time//3600:02}:{(total_time//60)%60:02}:{total_time%60:02}",fg= "#00FF00",font=("Arial", 24))
    rest_label.config(text=f"{(rest // 3600) % 3600:02}:{(rest // 60) % 60:02}:{rest % 60:02}",fg= "#00FF00",font=("Arial", 24))

############TIME FUNCTIONS#############################################

def countdown():
    global total_time,rest, pause
    if total_time > 0 and pause == "No":
        total_time -= 1
        countdown_label.config(text=f"{(total_time // 3600) % 3600:02}:{(total_time // 60) % 60:02}:{total_time % 60:02}",fg="#00FF00", font=("Arial", 24))
        root.after(1000,countdown)
        if total_time == 0:
            countdown_label.config(
                text=f"{(total_time // 3600) % 3600:02}:{(total_time // 60) % 60:02}:{total_time % 60:02}", fg="red",
                font=("Arial", 24))

    elif total_time == 0 and rest > 0 and pause == "No":
        rest -= 1
        rest_label.config(text=f"{(rest// 3600) % 3600:02}:{(rest // 60) % 60:02}:{rest % 60:02}", fg="#00FF00", font=("Arial", 24))
        root.after(1000,countdown)
        if rest == 0:
            rest_label.config(text=f"{(rest // 3600) % 3600:02}:{(rest // 60) % 60:02}:{rest % 60:02}", fg="red",
                              font=("Arial", 24))

def countdown_pause():
    global pause
    pause = "Yes"

def countdown_unpause():
    global pause
    pause = "No"
    countdown()

#############LABELS####################
countdown_label = tk.Label(text = "00:00:00",fg="#00FF00",bg='#2F4F4F', font=("Arial", 24))
countdown_label.grid(row= 0, column = 2, columnspan=2)

countdown_label_title = tk.Label(text = "RUNNING: ",fg="#00FF00",bg='#2F4F4F', font=("Arial", 24))
countdown_label_title.grid(row= 0, column = 0, columnspan=2)

rest_label = tk.Label(text = "00:00:00", fg= "#00FF00",bg='#2F4F4F',font=("Arial", 24))
rest_label.grid(row= 1, column = 2, columnspan=2)

rest_label_title = tk.Label(text = "RESTING: ",fg="#00FF00",bg='#2F4F4F', font=("Arial", 24))
rest_label_title.grid(row= 1, column = 0, columnspan= 2)

#BUTTONS###
add_button = tk.Button(root, text="START", command=countdown, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 3, column = 1)

add_button = tk.Button(root, text="+HOUR", command=add_time_hour, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 2, column = 0)

add_button = tk.Button(root, text="+MNTS", command=add_time_min, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 2, column = 1)

add_button = tk.Button(root, text="+SCND", command=add_time_sec, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 2, column = 2)

add_button = tk.Button(root, text="RESET ", command=reset, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 3, column = 0)

add_button = tk.Button(root, text="RST-MIN", command=add_rest_min, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 2, column = 3)

add_button = tk.Button(root, text="PAUSE", command=countdown_pause, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 3, column = 2)

add_button = tk.Button(root, text="RESUME", command=countdown_unpause, bg='#36648B', font=("Arial", 18))
add_button.grid(row= 3, column = 3)

root.mainloop()
🌐
ProgramCreek
programcreek.com › python › example › 2317 › threading.Timer
Python Examples of threading.Timer
def start(self, instance, fields=None, restore=None, send_update=None): """ Starts a threading.Timer chain, to repeatedly update a resource instances's expirationTime. @param instance: resource instance @param fields: additional fields mandatory during update @param restore: function that will restore the instance, if it has expired accidentally. Has to restart the refresher.
🌐
Stack Overflow
stackoverflow.com › questions › 64259270 › how-to-start-timer-and-reset-it-back-in-python
How to start timer and reset it back in python? - Stack Overflow
October 8, 2020 - otherwise start timer afresh print('restart_timer') if self.start_event.is_set(): self.reset_event.set() print('restart_timer:reset') else: self.start_event.set() print('restart_timer:start') def terminate(self): print('terminate') self.terminate_event.set() class Application(Tk): def show_idle_screen(self): for widget in self.winfo_children(): widget.destroy() # Create new widget element print('idle_screen') def show_product_info(self, barcodeno): # call web api and get response # create information widget element # -Timer(5.0, self.show_idle_screen).start() # -tmr = TimerThread(timeout, slee
🌐
Python
docs.python.org › 3 › library › threading.html
threading — Thread-based parallelism — Python 3.14.4 ...
Timers are started, as with threads, by calling their Timer.start method. The timer can be stopped (before its action has begun) by calling the cancel() method.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
Tkinter inactivity reset timer - Raspberry Pi Forums
I wanted to spin up some sort of ... if the timer reaches 0 the screen would reset back to my main screen for inactivity. I was looking in python at after(), but not sure how I would reset it if the user strikes a key. Also, if they do finish and move to the next screen I need to restart the countdown ...
🌐
CodeScracker
codescracker.com › python › program › python-program-shutdown-restart-computer.htm
Python Program to Shutdown and Restart Computer
Because to use + operator to concatenate two string values. That is, strOne and strTwo. The second string is the timer value entered by user. To restart your computer system using a python program, just replace the /s with /r from the program given to shutdown the system.
🌐
Python Pool
pythonpool.com › home › blog › understanding the python timer class with examples
Understanding the Python Timer Class with Examples - Python Pool
May 23, 2021 - You can export this class as a module and install it as a dependency in your code. Then by using a single line, you can import it – · import time class Timer: """ Timer class """ def __init__(self): self.start = time.time() ''' Restarts the timer.