There is nothing inherently wrong in this pattern. I have used the daemon function in init.d to start a very similar python script. As long as "do something" doesn't leak, it should be able to run forever.

Answer from stark on Stack Overflow
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python while Loop (Infinite Loop, break, continue) | note.nkmk.me
August 18, 2023 - Convert bool (True, False) and other types to each other in Python · start = time.time() while 1: time.sleep(1) print('processing...') if time.time() - start > 5: print('!!BREAK!!') break # processing... # processing... # processing... # processing... # processing... # !!BREAK!! ... In the sample code above, an infinite loop is used for explanation; however, the same operation can be performed without an infinite loop, as shown below.
Discussions

Always add some form of sleep in while True loops
Running a while True loop without anything in the loop to make the thread sleep will cause Python to use 100% CPU. Since ev3dev-stretch R3, this is especially noticeable since the user program is run with higher priority (nice -10) and i... More on github.com
🌐 github.com
1
July 31, 2020
python - Infinite loop with setting time of sleep - Stack Overflow
What exactly doesn't work? If I boil this down to while True: print('hello'); sleep(t) the sleep call works just fine ... Ok, it works. The problem was with sublime text. ... So putting True as condition, you will have a neverending loop. More on stackoverflow.com
🌐 stackoverflow.com
python - Sleep() function inside a infinite while loop - Stack Overflow
Is it possible for sleep function inside a while loop? I have this while loop which goes to infinity. When I add time.sleep(10) it breaks out of the loop after the second try. Is it possible to time. More on stackoverflow.com
🌐 stackoverflow.com
Efficient and fast Python While loop while using sleep() - Stack Overflow
I am attempting to communicate with a device over serial using Pyserial. As commands need to be continually sent, they have to be placed in a while loop in Python. I am currently using this code,... More on stackoverflow.com
🌐 stackoverflow.com
June 7, 2012
People also ask

What causes an infinite loop in a Python program?
An infinite loop in a Python program is typically caused by a loop's termination condition never being met. This may happen if the condition is always true, due to improper initialization, update of loop control variables, or logical errors in the loop's condition.
🌐
vaia.com
vaia.com › en-us › explanations › computer-science › computer-programming › python-infinite-loop
Python Infinite Loop: Definition & Examples | Vaia
What are the consequences of an infinite loop in Python programs?
An infinite loop can cause a program to become unresponsive, leading to high CPU usage and resource exhaustion. It may prevent other processes from running efficiently and can halt system performance. Debugging can be challenging, potentially resulting in prolonged downtime if not managed promptly.
🌐
vaia.com
vaia.com › en-us › explanations › computer-science › computer-programming › python-infinite-loop
Python Infinite Loop: Definition & Examples | Vaia
How can I detect an infinite loop in my Python program?
Detect an infinite loop by checking for high CPU usage or unresponsive behavior in your program. Use debugging tools like print statements to track loop iterations or integrate timeouts and break conditions to terminate loops exceeding expected execution time. Additionally, test for corner cases that could cause infinite repetition.
🌐
vaia.com
vaia.com › en-us › explanations › computer-science › computer-programming › python-infinite-loop
Python Infinite Loop: Definition & Examples | Vaia
🌐
Programiz
programiz.com › python-programming › time › sleep
Python sleep() (With Examples)
import time while True: # get current local time as structured data current_time = time.localtime() # format the time in 12-hour clock with AM/PM formatted_time = time.strftime("%I:%M:%S %p", current_time) print(formatted_time) time.sleep(1) ... In the above example, we obtain and print the ...
🌐
Linux Hint
linuxhint.com › using_python_sleep_method
Using the Python sleep() Method – Linux Hint
Four variables are used in the script to initialize the hour, minute, second, and counter variables to set the starting time of the time counter. Here, the sleep() function will wait for one second in each iteration of the loop and then print the time counter value.
🌐
StudySmarter
studysmarter.co.uk › computer science › computer programming › python infinite loop
Python Infinite Loop: Creation, Example & Error | StudySmarter
August 10, 2023 - To include the 'sleep()' function in your Python infinite loop code, follow these steps: 1. Import the 'time' module. 2. Utilise the 'sleep()' function within the loop block. 3. Pass the desired delay in seconds as an argument to the 'sleep()' function.
🌐
LinuxConfig
linuxconfig.org › home › python while loops
Master Python While Loops for Efficient Coding
February 24, 2017 - It’s fairly common to see sleep() in loops, especially infinite ones. One way to stop a while loop is to use a counting variable. Set the condition of the loop to the number where you want the loop to stop iterating, and increment the counting variable every time the loop runs.
Find elsewhere
🌐
GitHub
github.com › ev3dev › ev3dev-lang-python › issues › 754
Always add some form of sleep in while True loops · Issue #754 · ev3dev/ev3dev-lang-python
July 31, 2020 - The added sleep can be time.sleep() or anything that does a blocking wait for at least a millisecond or two (poll() with timeout, waiting for a sound to finish playing, etc.). Example programs, such as this one from the README should be modified similar to this: ts = TouchSensor() leds = Leds() print("Press the touch sensor to change the LED color!") while True: if ts.is_pressed: leds.set_color("LEFT", "GREEN") leds.set_color("RIGHT", "GREEN") else: leds.set_color("LEFT", "RED") leds.set_color("RIGHT", "RED") # don't use 100% CPU time.sleep(0.01)
Author   dlech
🌐
Real Python
realpython.com › python-sleep
Python sleep(): How to Add Time Delays to Your Code – Real Python
August 1, 2023 - The threading module provides an Event() that you can use like time.sleep(). However, Event() has the added benefit of being more responsive. The reason for this is that when the event is set, the program will break out of the loop immediately. With time.sleep(), your code will need to wait for the Python sleep() call to finish before the thread can exit.
🌐
Stack Overflow
stackoverflow.com › questions › 70977893 › infinite-loop-with-setting-time-of-sleep
python - Infinite loop with setting time of sleep - Stack Overflow
Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams ... import win32api, win32con, time def jump(x,y): x0, y0 = win32api.GetCursorPos() win32api.SetCursorPos((x0+x,y0+y)) t = int(input("type time of sleepin [s]: ")) while True: jump(10,10) time.sleep(t)
🌐
Net Informations
net-informations.com › python › pro › sleep.htm
How to pause execution of program in Python
The above program run an infinite loop, so you should forcefully stop the program when you want. The following program is a countdown example, using sleep method to wait 1 second each number. import time wait = 10 while wait > 0: print(wait) time.sleep(1) wait = wait - 1 · Threads are commonly hosted within processes, allowing multiple threads to coexist within a single process.
🌐
Purple Frog Systems
purplefrogsystems.com › home › how to delay a python loop
How to delay a Python loop - Purple Frog Systems
April 26, 2022 - The number of seconds that have passed this minute is calculated from date_time[-2:]. Subtracting this from 60 gives the length of time in seconds for which the loop should sleep for, to execute when the next minute starts. Once the loop has slept for the required number of seconds, we lookup the datetime again and print it out. 3 – Task Scheduler The previous two options are good for executing a loop a few times, ten in our case. If we wanted to execute a python script continuously without expiring, we could use the above examples with an infinite appending loop.
🌐
Board Infinity
boardinfinity.com › blog › sleep-in-python
Sleep() in Python | Board Infinity
August 14, 2025 - The real decorator(), a function that accepts the decorated function, is contained within the sleep() function. Last but not least, the innermost function wrapper() takes both keyword arguments and parameters passed to the decorated function. The magic happens right here! You try invoking the procedure once more by using a while loop.
🌐
Python.org
discuss.python.org › python help
Unable to quit infinite while loop in idle 3.12.0 (64 bit) with keyboard interrupt - Python Help - Discussions on Python.org
December 10, 2023 - Hello I am learning python, in IDLE when i write # infinite while loop i = 1 while i < 2: print(i) it produces an infinite while loop . But for some reason I am unable to use the keyboard interrupt (ctrl + C) Id…
🌐
nixCraft
cyberciti.biz › nixcraft › howto › linux › python sleep(): add delay in a seconds to suspend execution of a script
Python sleep(): Add Delay In A Seconds To Suspend Execution Of A Script - nixCraft
January 9, 2021 - Finally, add 1 second delay in a script using sleep(1) (line #15). Continue this procedure till user interrupts. The signal.signal() function allows defining custom handlers to be executed when a signal is received. #!/usr/bin/python # The following will run infinity times on screen till user hit CTRL+C # The program will sleep for 1 second before updating date and time again.