Python Forum
want command program: sleep to a specific time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
want command program: sleep to a specific time
#1
i would like to find a command program that sleeps, but instead of (or in addition to) sleeping a specified duration, sleep to a specified time or a specified date and time or a specified repeating interval (for example: sleep to next hour) or a specified repeating interval with an offset (for example: sleep to the next 20 minutes into the hour, which at 9:10 would sleep to 9:20) with support for negative offsets (for example: sleep to the next 5 minutes before end of day). i am open to ideas for the command syntax. making this also be a function would be a plus.
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
import time
import datetime


def calc_duration(s, m=0, h=0, d=0):
    return s + (m * 60) + (h * 3600) + (d * 3600 * 24)


def duration_until(target_datetime):
    """
    Here you need to add tzinfo, otherwise it would e wrong
    Maybe use another better module
    # look for http://arrow.readthedocs.io/en/latest/
    # or just read the documantation of datetime: https://docs.python.org/3/library/datetime.html
    """
    return (target_datetime - datetime.datetime.now()).seconds


duration = calc_duration(s=5, m=1)
time.sleep(duration)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
Linux at command?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
(Jul-10-2017, 08:34 PM)wavic Wrote: Linux at command?

this is not really a sleep type of command.  it is more of an interactive cronjob type of thing.  but has a nice time-forward text interpreter that could be a plus as a python function (given a datetime value and the text to interpret, return an updated datetime value).
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
  sleep to half past the hour Skaperen 11 3,933 Oct-29-2020, 06:41 AM
Last Post: Skaperen
  opening python from the command line takes a long time to load? abdulkaderanwar 4 2,981 Jun-22-2020, 03:42 AM
Last Post: abdulkaderanwar
  my ideas for a new sleep command Skaperen 1 1,950 Sep-02-2019, 04:17 AM
Last Post: Larz60+
  wanted: python code: sleep to a time period Skaperen 2 6,578 Nov-06-2017, 03:00 AM
Last Post: Skaperen
  program to code: log results of a command Skaperen 0 2,016 Sep-20-2017, 03:37 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