Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my nsleep command
#1
i've already implemented this in C. now, i want to make a Python version.

nsleep is similar to the sleep command but it takes up to 3 arguments to specify how long to sleep, or when to sleep to. the 1st argument is simply the minimum amount of time to sleep. if given alone, then it is the amount of time to sleep. the 2nd argument is the cycle period. if 60 is given (or an equivalent expression like "1m") then the cycle is every minute. the 3rd argument, which must be smaller than the 2nd, is the cycle offset that shifts the cycle period (positive to the future). if the 3rd argument is not given, it defaults to 0, which does no shifting of the cycle period. so if the 2nd and 3rd arguments are 3600 and 300 (or "1h" and "5m") then the meaning is "five minutes after each hour". if the current time is 7:03, then it would sleep for 120 seconds (if the 1st argument is not larger). if the current time is 7:10, then it would sleep for 3300 seconds (55 minutes to 8:05).

this is how i have things repeat without any accumulated offset. my command history will show a lot of "while nsleep ...". many repeating shell scripts use nsleep, too.

for the Python version, i plan to make a function that does it based on 3 arguments given as int float or decimal.Decimal. the time period calculation will be done by that function, probably to be named nsleep(). then the command code will add support for suffix multipliers up to weeks.

i hope i explained that clear enough.
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
my old C code is here: http://ipal.net/free/nsleep.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


Forum Jump:

User Panel Messages

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