Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Timer Question
#1
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.
Reply
#2
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?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.

My Scripts
CookBook - Shmup - PyQt5 Music Player


Reply
#3
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)
Reply
#4
thank you! that works great.
i'm using shell.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple code question about lambda and tuples JasPyt 7 426 Oct-04-2021, 05:18 PM
Last Post: snippsat
Big Grin question about simple algorithm to my problem jamie_01 1 211 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  email timer/rss feed timer ndiniz 1 730 Feb-02-2021, 07:18 PM
Last Post: nilamo
  Simple question 1234 4 731 Dec-04-2020, 12:29 PM
Last Post: DeaD_EyE
  Simple question on tab stuartsmith22 4 1,012 Apr-15-2020, 04:42 PM
Last Post: stuartsmith22
  Simple question concerning python dot notation. miner_tom 1 727 Mar-24-2020, 05:20 PM
Last Post: buran
  Simple question about .format(* ) Motley_Cow 1 996 Oct-03-2019, 07:13 AM
Last Post: buran
  Simple newb string question Involute 2 1,085 Sep-08-2019, 12:50 AM
Last Post: Involute
  simple syntax question speedskis777 7 1,706 Mar-11-2019, 02:26 AM
Last Post: snippsat
  Simple question - ERROR UnitedK 1 1,205 Sep-24-2018, 11:11 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020