How do I have a python script that contains functions say function1, function2, and function3 that I want to execute every 24 hours as a separate process/thread? So say…
Main Application executes function1, function2
function1 and function2 executes some long running process in a separate threads from the main application
once function 1 finishes its task, reports back to main application that it completed
Main application prints “Done with Function 1.”
once function 2 finishes its task, reports back to main application that it completed
24 hours after function 1 finishes… the main app will execute it again
6 hours after function 2 finishes… the main app will execute the function again
Note that the functions would be doing similar things, but the data source is different, so having separate apps and doing a cron is undesirable.
Examples would be great.
If you need it inside the application,
alarm()is a good place to start, and handler shouldfork()itself off. If you need to synchronize different functions at different intervals,PriorityQueueis great, as you can only maintain one alarm. There is a workingalarm()example in the docs.Otherwise, I’d probably go with separate applications, not functions, and trigger them by
crontab.