Python Forum

Full Version: Simple Timer Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all -
I'm new to Python, so I apologize for this post - I'm not exactly sure what to be looking for, since when you search for "Python" and "Timer", there's an avalanche of information.

Essentially, what I'd like to do is run a timer in the background that executes a bit of code (let's say a print function) at a specified, recurring interval (let's say once every minute).

I'm using Python 3.7, if that changes the nature of the answer at all.

Thanks.
In my opinion, that's kind of a broad question.
Are you going to be using a gui, shell, or some other way of executing the code?
What you describe is event scheduling,there is a build in sched.
What i have used before is schedule(easy to use) and APScheduler(more advance).
# pip install schedule
import schedule
import time

def p1():
    print("Hello")

def p2():
    print("World")

schedule.every(10).seconds.do(p1)
schedule.every(11).seconds.do(p2)

while True:
    schedule.run_pending()
    time.sleep(1)
thank you! that works great.
i'm using shell.