You can schedule your job at the nearest minute, then use alarm
to get second-level precision. For an example in Python:
from signal import signal, setitimer, ITIMER_REAL, SIGALRM, alarm
from datetime import datetime, time
from sys import argv, exit
from time import sleep
at = datetime.combine(datetime.now(), time.fromisoformat(argv[1]))
class Done(Exception):
pass
def _handler(signum, frame):
print("The time is", datetime.now())
raise Done()
setitimer(ITIMER_REAL, (at - datetime.now()).total_seconds())
signal(SIGALRM, _handler)
try:
while True:
sleep(1)
except Done:
pass
Running:
$ python at-second.py 13:36:28
The time is 2022-07-06 13:36:28.000238
A limitation for this method:
only one alarm can be scheduled at any time
So if you need multiple events in a minute, you'd need to schedule the second one only after the first one is finished.
time sleep 5
give me an extra.003
seconds. Try that command on your machine to see how accurate it will be.