473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is inifinite loop not a good practice?

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!
Feb 20 '06 #1
1 1808
Alvin A. Delagon enlightened us with:
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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Feb 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
13
by: na1paj | last post by:
here's a simple linked list program. the DeleteNode function is producing an infinit loop i think, but i can't figure out where.. #include <stdio.h> typedef struct { char *str; //str is a...
63
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.