Is inifinite loop not a good practice?

Discussion in 'Python' started by Sybren Stuvel, Feb 20, 2006.

  1. 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
     
    Sybren Stuvel, Feb 20, 2006
    #1
    1. Advertisements

  2. Greetings,

    I have to write a python script that would continously monitor and
    process a queue database. Once the script sees an unprocessed record it
    will create a thread to process it otherwise it will do nothing. 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'm opted to run the script via crontab but I consider it as
    my last resort. Do you have any suggestions on the design? Thanks in
    advance!
     
    Alvin A. Delagon, Feb 20, 2006
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.