testing machine responsiveness

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Mon Oct 9 00:26:06 CEST 2006

In message <eg5kjf$ona$1 at foggy.unx.sas.com>, Tim Arnold wrote:

>         try:
>             s.connect((cpu,7))
>         except:
>             return 0
>         try:
>             s.send('test')
>             s.recv(128)
>             s.close()
>             return 1
>         except:
>             return 0

Call me nervous, but I like to make my "except" clauses as specific as
possible, to catch only the errors I'm expecting. This is to minimize the
chance of some hidden bug sneaking through and causing the wrong behaviour.

>         try:
>             rup = os.popen('rup %s | sort -n -t, -k4 | grep day' %
> (self.asString))
>         except OSError:
>             return self.asList

So if the rup call fails, you're returning a plain list of all the
hostnames? Won't this cause the following parsing to fail?

If you're going to trigger a failure, isn't it better for it to happen as
close as possible to the actual cause? In other words, take out the
try/except block above and let the os.popen call itself directly signal an
exception on failure.

Disclaimer: I've never actually used rup. :)

More information about the Python-list mailing list