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
🌐
Python
docs.python.org › 3 › library › timeit.html
timeit — Measure execution time of small code snippets
The repetition count (‘best of 5’) which tells you how many times the timing loop was repeated, and finally the time the statement body took on average within the best repetition of the timing loop. That is, the time the fastest repetition took divided by the loop count. >>> import timeit >>> timeit.timeit('char in text', setup='text = "sample string"; char = "g"') 0.41440500499993504 >>> timeit.timeit('text.find(char)', setup='text = "sample string"; char = "g"') 1.7246671520006203 · The same can be done using the Timer class and its methods:
🌐
Real Python
realpython.com › python-timer
Python Timer Functions: Three Ways to Monitor Your Code – Real Python
December 8, 2024 - As you can tell, perf_counter() is usually the best choice for your Python timer.
Discussions

python - How can I write a loop to make the timer run every two seconds - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I have a question on how I am able to set the timer so that every time it exits the loop it sets the time back to 2 seconds. The problem is that the first time the sound works after 2 seconds, ... More on stackoverflow.com
🌐 stackoverflow.com
How to make a timer ?
sounds like you can use the time, module for this or schedule module along with time coukd work as well. Im still a beginner too. https://www.geeksforgeeks.org/python-time-module/ More on reddit.com
🌐 r/learnpython
3
3
August 14, 2024
How To Use Timer With Loop in Python - Stack Overflow
Use tab or spacebar or whatever you used at the start of line 7: "global continue_looping" 2013-05-24T02:48:11.65Z+00:00 ... Thank you! But now it gives different error. Traceback (most recent call last): File "serial-reader.py", line 12, in timer.start() File "/Library/Frameworks/Python.... More on stackoverflow.com
🌐 stackoverflow.com
python - How to repeatedly execute a function every x seconds? - Stack Overflow
I want to repeatedly execute a function in Python every 60 seconds forever (just like an NSTimer in Objective C or setTimeout in JS). This code will run as a daemon and is effectively like calling ... More on stackoverflow.com
🌐 stackoverflow.com
September 16, 2019
🌐
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 ...
🌐
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 ! 🐍

🌐
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
import time count = 0 while True: do_something(count) count += 1 time.sleep_ms(100) However since it takes time to execute do_something() each iteration of this loop is going to take slightly longer then 100ms. Assuming that do_something() takes anywhere between 10 and 40 ms to finish, the question is what is the 'best' way in MicroPython to start to execute do_something() exactly every 100ms..? Thanks ... while True: t = time.ticks_ms() do_something() while time.ticks_diff(time.ticks_ms(), t) < 100: pass ... Maybe turn it inside out and use a Timer instead.
Find elsewhere
🌐
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()
🌐
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. · GitHub
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
🌐
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
🌐
GitHub
github.com › dbjohnson › looptimer
GitHub - dbjohnson/looptimer: Loop timer with projected time-to-completion
January 25, 2021 - Progress bar style loop timer with projected time-to-completion.
Author   dbjohnson
🌐
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).
🌐
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, ...
🌐
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.
🌐
Medium
blog.esciencecenter.nl › pythons-timeit-find-the-fastest-code-in-no-time-23d6092b5c72
Python’s timeit: Find the fastest code in no time | by Sander van Rijn | Netherlands eScience Center
May 14, 2024 - $ python -m timeit -s 'text = "sample string"; char = "g"' 'char in text' 20000000 loops, best of 5: 19 nsec per loop $ python -m timeit -s 'text = "sample string"; char = "g"' 'text.find(char)' 5000000 loops, best of 5: 69.3 nsec per loop ...