S
Sybren Stuvel
Alvin A. Delagon enlightened us with:
I think it's just fine. You could improve it a bit by using something
like:
class Monitor(Thread):
def __init__(self, *args, **kwargs):
Thread.__init__(self, *args, **kwargs)
self.interrupted = False
def run(self):
while not interrupted:
monitor()
def interrupt(self):
self.interrupted = True
The advantage there is a stability issue. If your program quits,
you've got a problem. Using crontab, the program is started over and
over again, so even if it crashes, it'll be restarted in time for the
next monitor run. Cron has been around for such a long time that the
chance of a crash is much less than with a freshly developed program.
Sybren
I have to write a python script that would continously monitor and
process a queue database. [...] I've been planning to do an infinite
loop within the script to do this but I've been hearing comments
that infinite loop is a bad programming practice.
I think it's just fine. You could improve it a bit by using something
like:
class Monitor(Thread):
def __init__(self, *args, **kwargs):
Thread.__init__(self, *args, **kwargs)
self.interrupted = False
def run(self):
while not interrupted:
monitor()
def interrupt(self):
self.interrupted = True
I'm opted to run the script via crontab but I consider it as my last
resort.
The advantage there is a stability issue. If your program quits,
you've got a problem. Using crontab, the program is started over and
over again, so even if it crashes, it'll be restarted in time for the
next monitor run. Cron has been around for such a long time that the
chance of a crash is much less than with a freshly developed program.
Sybren