I am not sure if you meant that, but for me it seems like you just want to wait 2 seconds before executing the next steps. You can do that like so:

import time

while True:
    time.sleep(2) # waits 2 seconds
    winsound.Beep(440, 1000)

Anyways I don't recommend you to use a plain infinite loop, without a break statement. Therefore I recommend you to add one, like down below.

import time

while True:
    time.sleep(2) # waits 2 seconds
    winsound.Beep(440, 1000)

    if True: # break on a specific statment
        break

Edit: As CrazyChucky mentioned in the comments, this approach should work fine in most of the cases, but it can end up being more than two seconds sometimes. Therefore you should work with timedeltas or take a look at scheduler.

Answer from Maik Hasler on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › how to make a timer ?
r/learnpython on Reddit: How to make a timer ?
August 14, 2024 -

Hello guys ! I’m starting with python a week ago, I don’t have all the knowledge etc…, but I’m very curious and I wish to know a method or how to make a Timer in python… like my timer start at 35min and decrease to 0 or to 0 to 35. If anybody have an idea how to do this, I'll take it !! See you ! 🐍

Discussions

How To Use Timer With Loop in Python - Stack Overflow
I want to listen serial port and save it for every 15 seconds. But I can't use time in loop. It gives an error as below. File "serial-reader.py", line 13 timer.start() ^ More on stackoverflow.com
🌐 stackoverflow.com
time - Python loop to run for certain amount of seconds - Stack Overflow
I have a while loop, and I want it to keep running through for 15 minutes. it is currently: while True: #blah blah blah (this runs through, and then restarts. I need it to continue doing this ... More on stackoverflow.com
🌐 stackoverflow.com
How to Create a Loop That Runs Every 5 Minutes
Hi. Since this is such a simple problem, I’d usually just solve it myself, but since school has started, I have way less time for personal projects. So I have a Discord bot with an events function that I made. Basically, it checks every minute to see if it has a task to do. More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
September 12, 2022
Using a while loop and calling threading Timer?
Do you mean wait up to X seconds until a file is present and then do something? def Timer(time_limit): while time.time() < now + time_limit: success = False if os.path.exists(file): # Do anything you want if the file exists success = True break else: # Just wait, we don't want to burn the CPU time.sleep(0.5) return success I tried to read your code but it doesn't look like something it can work. More on reddit.com
🌐 r/learnpython
7
1
March 21, 2017
🌐
Codecademy
codecademy.com › forum_questions › 51350be40ca99a88590017cc
How can I control a loop with time? | Codecademy
So check out this timed loop. import time print("begin timer") measure1 = time.time() measure2 = time.time() count = 1 while count < 11: if measure2 - measure1 >= 2: print("two seconds") measure1 = measure2 measure2 = time.time() count += 1 ...
🌐
Real Python
realpython.com › python-timer
Python Timer Functions: Three Ways to Monitor Your Code – Real Python
December 8, 2024 - Using a timer involves recording timestamps before and after a specific code block and calculating the time difference to determine how long your code took to run. [ ... ] ## Read the full article at https://realpython.com/python-timer/ » * * *
🌐
Python
docs.python.org › 3 › library › timeit.html
timeit — Measure execution time of small code snippets
Time number executions of the main statement. This executes the setup statement once, and then returns the time it takes to execute the main statement a number of times. The default timer returns seconds as a float.
🌐
GitHub
github.com › morefigs › interval-timer
GitHub - morefigs/interval-timer: interval-timer is a Python package that enables iterating over a sequence of regular time intervals with high precision.
IntervalTimer is a more precise replacement for a loop that contains a wait. The following code: from time import sleep # Iterates approximately every half second for i in range(5): print(i) sleep(0.5) ... from interval_timer import IntervalTimer ...
Author   morefigs
Find elsewhere
🌐
GitHub
github.com › ovinc › oclock
GitHub - ovinc/oclock: Python 3 package with tools for timed, no-drift loops of constant duration, and other misc. timing tools (GUI countdown, context managers etc.)
oclock is a Python 3 package. Its main goal is to provide a simple way to create timed loops with constant time intervals and no drift. It also provides various other timing tools and a GUI timer.
Starred by 7 users
Forked by 4 users
Languages   Python 100.0% | Python 100.0%
🌐
Medium
medium.com › @andrewdass › how-to-make-a-timer-in-python-76cd679c5725
How to make a Timer in Python. Overview | by Andrew Dass | Medium
December 30, 2023 - Then the second else statement will run, and the if statement will execute and break out of the while loop. inserted_time = datetime.datetime(insert_year, insert_month, insert_day, insert_hour, insert_minute, insert_seconds) print("The timer will stop when it reaches this date and time:", inserted_time) while True: if datetime.datetime.now() > inserted_time: break else: print("Current time:", datetime.datetime.now()) print("Time is still going...") difference_in_time = inserted_time - datetime.datetime.now() print("Time left: ", difference_in_time) if (difference_in_time.total_seconds()) > 10: time.sleep(10) print("10 seconds has passed.") else: time.sleep(difference_in_time.total_seconds()) print("Less than 10 seconds has passed.") print("Program Finished.")
🌐
Udacity
udacity.com › blog › 2021 › 09 › create-a-timer-in-python-step-by-step-guide.html
Create a Timer in Python: Step-by-Step Guide | Udacity
September 27, 2022 - Let’s now build a countdown timer. This example incorporates both the datetime module and the time.sleep() function. Take a look at the program below: import time import datetime # Create class that acts as a countdown def countdown(h, m, s): # Calculate the total number of seconds total_seconds = h * 3600 + m * 60 + s # While loop that checks if total_seconds reaches zero # If not zero, decrement total time by one second while total_seconds > 0: # Timer represents time left on countdown timer = datetime.timedelta(seconds = total_seconds) # Prints the time left on the timer print(timer, end="\r") # Delays the program one second time.sleep(1) # Reduces total time by one second total_seconds -= 1 print("Bzzzt!
🌐
freeCodeCamp
forum.freecodecamp.org › python
How to Create a Loop That Runs Every 5 Minutes - Python - The freeCodeCamp Forum
September 12, 2022 - Hi. Since this is such a simple problem, I’d usually just solve it myself, but since school has started, I have way less time for personal projects. So I have a Discord bot with an events function that I made. Basically, it checks every minute to see if it has a task to do.
🌐
Python Forum
python-forum.io › thread-33121.html
Timing of a while loop
I have a while loop that is happening every 30 seconds def modelTimer(): starttime = time.time() timeout = time.time() + 60*60*6.5 while time.time()
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › micropython
Executing the code in a loop at a fixed interval. - Raspberry Pi Forums
See the Micropython "blink with a timer" example which uses 'machine.Timer'. You give it a rate and a callback function, and the routine gets called at that rate (more or less, assuming nothing else is hogging the system).
🌐
JetLearn
jetlearn.com › blog › how-to-create-a-timer-in-python
How to Create a Timer in Python: A Step-by-Step Guide
February 24, 2025 - ‍ · 2. Set the Timer Duration: Define the duration of the timer in seconds. For example, to set a timer for 10 seconds. ‍ · 3. Create the Countdown Loop: Use a loop to count down from the specified duration to 0.
🌐
PyPI
pypi.org › project › loopytimer
Client Challenge
February 11, 2018 - 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 Assets
pythonassets.com › posts › executing-code-every-certain-time
Executing Code Every Certain Time | Python Assets
March 13, 2022 - How to a run a Python function in the background at regular intervals (also known as timer) using the «threading» standard module.
🌐
PyPI
pypi.org › project › multitimer
multitimer · PyPI
A pure-python auto-repeating timer that can be stopped and restarted multiple times.
      » pip install multitimer
    
Published   Nov 27, 2020
Version   0.3
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-create-a-countdown-timer-using-python
How To Create a Countdown Timer Using Python? - GeeksforGeeks
May 9, 2025 - Follow the below steps to create a countdown timer: ... Use divmod(t, 60) to convert seconds to minutes and seconds. Format the time string using '{:02d}:{:02d}'.format(mins, secs).
🌐
Reddit
reddit.com › r/learnpython › using a while loop and calling threading timer?
r/learnpython on Reddit: Using a while loop and calling threading Timer?
March 21, 2017 -

Hi all,

I'm trying to write a function which says while the current time is less than the time limit, check if a file exists. Else, start the timer which the arguments are an interval, and the function itself to recheck for the file and join a 'timeout'.

However, it doesn't seem to like being in a while loop and spews an error message stating can't start another thread.

I've tried throwing in a cancel, but no luck.

My code:

t = Timer(check_intervals, watch_file) while time.time() < now + time_limit: if.os.path.exists(file): return True else: t.start() t.join(time_limit)

How can I refine this to work?

Thanks!