1

For a python project, I have to scheduele task at specific time like :

"execute a cat every 26 of the month at 1pm03"

the command takes in entry the minute, hours, day of month...

I just don't find any answer on how to handle properly a scheduler without using something like schedule library or any external library.

Do you have any advice on how to do that ?

Thank you

Tikroz
  • 161
  • 1
  • 13
  • Use the [at command](https://en.wikipedia.org/wiki/At_(Unix)) in Unix or [schtasks.exe](https://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx) in Windows environments. [This](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python) post nicely describes how you would call them from Python using only the standard library. – bboll Jan 03 '18 at 04:48
  • The aim of my project is to create my own scheduler of task, i don't think that i can use external things except things like time,datetime,sys... – Tikroz Jan 03 '18 at 04:51
  • 2
    This sounds a bit like homework (or *learning exercise*) right? It's ok... If it's an exercise and you can't use external libraries, you can use a `Timer`: calculate difference in seconds between now and the 26th of the month and schedule a Timer for then. See https://docs.python.org/2/library/threading.html#timer-objects Keep in mind that the `Timer` will have to re-schedule itself for the next 26th of next mont after being run. And also that if your script dies, the Timer will also die (but again, I'm assuming this is more of a learning exercise) – BorrajaX Jan 03 '18 at 04:51
  • Yes, it's a learning exercice, i don't ask for the answer by the way, just some clues, i currently use datetime and build a datetime from the given month, day, minutes... Is it a good solution ? – Tikroz Jan 03 '18 at 05:11
  • It's a start... You still need to know how many seconds from `now` to that datetime, and schedule "something" (namely a Timer) that will run the `cat` function in X seconds from `now` – BorrajaX Jan 03 '18 at 05:13
  • 1
    @BorrajaX You are probably correct. I got a little hung up on semantics since they are system commands, not libraries, and I figured learning to use the subprocess module might also be a good learning exercise. – bboll Jan 03 '18 at 05:16
  • 1
    Oh, @bboll... No, no... I agree!! Doing something like this for an actual production environment without support of a reaaaally well tested tool that doesn't "randomly die without serializing the schedules to file" (such as `cron`, `at` or `Celery-Beat` would be suicidal!!) However, the way the OP worded the question, sounds like an exercise to learn to work with `datetimes` and `Threads` (erm... `Timer`s rather) – BorrajaX Jan 03 '18 at 05:20
  • Thank you for all your answer, i still have problem with my programm, i don't know how to handle something like "*" for an unkown parameters depending the case. I also don't know how to properly set something to be sure the dates are correct – Tikroz Jan 03 '18 at 20:37

0 Answers0