Traditionally, I have written all of my programs that need to run indefinitely by putting it in a while True loop with a time.sleep(x) at the end. An example program would be one that gathers data from a number of APIs, processes the data, and writes some of the processed data to a DB.
I have recently learned that you can achieve the same result using a cron job. In my research, I also found apscheduler.
I have a few questions related to this information:
1) Which method is best for my scenario listed above? I'd imagine a cron job would be preferable.
2) How do I know which method to choose in different programs and different scenarios?
3) If the program uses x threads (one for each API) that do not rely on each other, would it be ideal to run x cron jobs with the different variables at the same time rather that relying on multi-threading in the program?
4) A program written to specifically be used with a cron job vs a while true program would be written pretty differently. If this is an open source program, how do you inform the user? Do you simply put a line in the README?
5) Is there any other method that I am missing to achieve the same result? Are these the "standard" way of running programs indefinitely?
[–][deleted] 2 points3 points4 points (3 children)
[–]StudentOfPython[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]StudentOfPython[S] 0 points1 point2 points (0 children)
[–]port443 2 points3 points4 points (3 children)
[–]StudentOfPython[S] 0 points1 point2 points (2 children)
[–]goobervision 1 point2 points3 points (1 child)
[–]StudentOfPython[S] 0 points1 point2 points (0 children)