0

I have a Python file on a Unix server, that will run 18 hours a day. The file will be run with Cron each day. The file has A while True loop with sleep. Assuming there is no uncaught exception, can this file run for this long? or how long can it run? I have a background in PHP, and know there is a maximum execution time, is there a such thing in Python?

Hef
  • 606
  • 6
  • 16
  • 1
    The question is based on a misconception and does not make sense as asked. Programs can, in their natural state, run for as long as the machine permits them to. Any limit in PHP is not inherent to PHP, either; it is imposed from outside (in the INI config), so that human supervision is not necessary to deal with programs that go into an infinite loop. It also [can be disabled](https://stackoverflow.com/questions/16171132). That said, if the program is going to be run daily, it needs to stop (or be stopped) in between. – Karl Knechtel Jun 11 '22 at 17:50
  • A python script without bugs will run forever ... mostly. Some objects can build up like logging handlers (don't make millions of logging handlers) or unjoined threads. The PHP timeout is mostly because its a web server where timeouts serve a purpose. – tdelaney Jun 11 '22 at 17:53
  • Keep in mind that any program, in any language, can be interrupted by external factors not under the program's control - for example, loss of power to the machine. – Karl Knechtel Jun 11 '22 at 17:53
  • @tdelaney "Some objects can build up like logging handlers (don't make millions of logging handlers) or unjoined threads." - That would be a bug. – Sören Jun 11 '22 at 17:56
  • @Sören if Cron and infinite loops contradict each other, is there a different way I could achieve something similar? – Hef Jun 11 '22 at 18:06
  • After re-reading your question: Does your "infinite" loop only run for 18 hours, and the program is restarted daily via cron? If that's the case, forget what I've been saying. – Sören Jun 11 '22 at 18:18

1 Answers1

0

Yeah, no problem. Python files are interpreted without such configuration in mind, so the process will run as long as you need it to.

Captain Trojan
  • 2,800
  • 1
  • 11
  • 28