Python Forum
sleep to half past the hour
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sleep to half past the hour
#1
a script needs to sleep to half past the hour. how would you do it?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
What about using the sched module?
Reply
#3
schedule
import schedule
import time

def drink():
    print("Time for a drink again...")

schedule.every().hour.at(":30").do(drink)

while True:
    schedule.run_pending()
    time.sleep(1)
Reply
#4
it does not need to be run every :30. it just needs to sleep to the next :30 this one time after running some big slow stuff.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
(Oct-23-2020, 07:32 PM)Skaperen Wrote: it does not need to be run every :30. it just needs to sleep to the next :30 this one time after running some big slow stuff.
Can of course configure this as you want,can look some post where use schedule.
check process, make file .

Also used APScheduler some times,
strong point eg that BackgroundScheduler dos separate thread automatic,so eg when i used it Flask or any other long running task it will not interfere with what is running.

schedule has also jobs in parallel,but has to manually import threading.
Reply
#6
the function i wrote would be called like sleep_cycle(3600,1800).

source posted here.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
(Oct-24-2020, 10:24 PM)Skaperen Wrote: the function i wrote would be called like sleep_cycle(3600,1800)
sleep() for longer time does not guarantee scheduling after the time given.
It just guarantees to sleep at least this time.
It can very well sleep longer, depending on system load.
sleep() is also a blocking,block the main thread from continuing to run while it waits for the sleep() call to end wait().

The two libraries i have posted about do of course not use sleep as time keeper,but time and datetime for that task.
time.sleep(1) in schedule is just used as a delay in the while loop,not as a time keeper.
Reply
#8
you saying i should redesign this?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#9
(Oct-25-2020, 06:33 PM)Skaperen Wrote: you saying i should redesign this?
That's up you not my task,i just point out what problems with that approach could be.
As usually you can not use libraries that put some thought into these schedule⏱ tasks,and work fine.
Reply
#10
if those libraries provided what i need, such as sleep to an expressed time, i think i would be using them. the script i made this for does a big batch of conversions then waits for the best time to queue up some big transfer jobs so they spend minimal time taking up space in the queue. the transfer server would be the one to use schedule, except that it's all done years ago ... in C.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my ideas for a new sleep command Skaperen 1 1,983 Sep-02-2019, 04:17 AM
Last Post: Larz60+
  want command program: sleep to a specific time Skaperen 3 3,599 Jul-11-2017, 01:33 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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