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.

Asked By: helpVulcan

||

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?

  1. Your app might have memory leaks (well, Python not so much) and it runs more stable when it’s restarted every time.
  2. 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.
  3. Your app may crash and no longer do what you expect to be done at every interval
  4. The user may (accidentally?) terminate your app with the same effect

Why not / when not?

  1. 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).
Answered By: Thomas Weller
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.