Better way of excuting a always running app?
Question:
Good day.
I have a question about the correct way of implemting code that needs to run every 5 minutes.
Is it better to:
- A – Inside the code have a timeloop that starts after 5 minutes, and
executes.
- B – Have a script that runs every 5 minutes and executes your
application.
- C – Other?
BG: This will be running on a windows server 2022, to send mail every 5 minutes if certain condations where met.
Thank you.
Answers:
B.) The script is named Windows Task Scheduler and comes with permission management etc.. A Windows server admin can tell you about it.
Why?
- Your app might have memory leaks (well, Python not so much) and it runs more stable when it’s restarted every time.
- An app that sleeps still uses memory, which may be swapped to disk and read back when it awakes. If the app terminates, the memory will be freed and not be swapped to disk.
- Your app may crash and no longer do what you expect to be done at every interval
- The user may (accidentally?) terminate your app with the same effect
Why not / when not?
- If the time to initialize the app (e.g. reading data from database or disk) takes a long time (especially longer than the sleep time).
Good day.
I have a question about the correct way of implemting code that needs to run every 5 minutes.
Is it better to:
- A – Inside the code have a timeloop that starts after 5 minutes, and
executes. - B – Have a script that runs every 5 minutes and executes your
application. - C – Other?
BG: This will be running on a windows server 2022, to send mail every 5 minutes if certain condations where met.
Thank you.
B.) The script is named Windows Task Scheduler and comes with permission management etc.. A Windows server admin can tell you about it.
Why?
- Your app might have memory leaks (well, Python not so much) and it runs more stable when it’s restarted every time.
- An app that sleeps still uses memory, which may be swapped to disk and read back when it awakes. If the app terminates, the memory will be freed and not be swapped to disk.
- Your app may crash and no longer do what you expect to be done at every interval
- The user may (accidentally?) terminate your app with the same effect
Why not / when not?
- If the time to initialize the app (e.g. reading data from database or disk) takes a long time (especially longer than the sleep time).