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

Python: Run code every n seconds and restart timer on condition - Stack Overflow
After 15 mins of no movement I ... and restart the time. ... The description sounds similar to a dead main's switch / watchdog timer. How it is implemented depends on your application: whether there is an event loop, are there blocking functions, do you need a separate process for proper isolation, etc. If no function is blocking in your code: #!/usr/bin/env python3 import time ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
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
while loop - A timer that restarts on a trigger Python - how to restart? - Stack Overflow
Bit of a newbie so bear with: I am trying to make a crude 60s timer that is reset and starts again on the rising edge of a trigger (ie when a gate goes high). The problem I have is that it won't re... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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
๐ŸŒ
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 ...
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ programming โ€บ python
A resetable background timer? - Raspberry Pi Forums
Possibly SIGALRM will do what you want. There's documentation and an example at http://docs.python.org/2/library/signal.html.
Find elsewhere
๐ŸŒ
Python
mail.python.org โ€บ pipermail โ€บ tutor โ€บ 2012-November โ€บ 092767.html
[Tutor] Reusing Timers (threading.timer)
November 14, 2012 - > > if autoUpdates is enabled > get updateFrequency > start timer with time value from updateFrequency > when time is reached, run update method > else > cancel timer Well that won't work, because once the update has run, it will stop checking for new updates.
๐ŸŒ
GitHub
gist.github.com โ€บ alexbw โ€บ 1187132
A repeating timer in Python ยท GitHub
September 1, 2011 - def __init__(self, function, interval, *args, **kwargs): super(RepeatingTimer, self).__init__() self.args = args self.kwargs = kwargs self.function = function self.interval = interval def start(self): self.callback() def stop(self): self.interval = False def callback(self): if self.interval: self.function(*self.args, **self.kwargs) Timer(self.interval, self.callback, ).start()
๐ŸŒ
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()
๐ŸŒ
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))
๐ŸŒ
Real Python
realpython.com โ€บ python-timer
Python Timer Functions: Three Ways to Monitor Your Code โ€“ Real Python
December 8, 2024 - In this step-by-step tutorial, you'll learn how to use Python timer functions to monitor how quickly your programs are running. You'll use classes, context managers, and decorators to measure your program's running time. You'll also learn the benefits of each method and which to use given the ...
๐ŸŒ
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.
๐ŸŒ
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 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, sleep_chunk, Application().s
๐ŸŒ
Super Fast Python
superfastpython.com โ€บ home โ€บ tutorials โ€บ how to restart a thread in python
How to Restart a Thread in Python - Super Fast Python
September 11, 2022 - Tying this together, the complete example of simulating a thread restart with a new instance is listed below. Running the example first creates the thread and runs it as before. The main thread joins the new thread until it terminates. The main thread then creates a new thread instance with the same configuration, starts it, and joins it. As we expect, this new thread executes without incident. Overwhelmed by the python concurrency APIs?
๐ŸŒ
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 ...