How robust is Python ?

Steve Holden sholden at holdenweb.com
Fri Jan 12 11:06:00 EST 2001


"Sandipan Gangopadhyay" <sandipan at vsnl.com> wrote in message
news:mailman.979313781.1111.python-list at python.org...
>
> ----- Original Message -----
> From: "Moshe Zadka" <moshez at zadka.site.co.il>
> To: <rturpin at my-deja.com>
> Cc: <python-list at python.org>
> Sent: Saturday, January 06, 2001 4:09 PM
> Subject: Re: How robust is Python ?
>
> > On Fri, 05 Jan 2001, rturpin at my-deja.com wrote:
> >
> > > Unfortunately, cron is not cross-platform. We'll have
> > > some sort of mechanism to do this. The problem is not
> > > just the language and operating system, but everything
> > > that can kill a process. Still .. you want such mechanism
> > > as backup, not as a solution to regular crashes.
> >
> > Of course. None of this is meant to imply Python crashes regularily.
> > In fact, I can't think off-hand of a language less likely to suffer
> > crashes, given that you take a few exception-catching precautions
> > in the main loop (have a catch-all except: which re-execs the process).
>
> I want this in my code, but came across a problem -
>
> while binAliveMarker:
>   if binIWannaStartAgain:
>     time.sleep(1)
>     continue
>   work code ...
>
> If I try a catch-all except, continue hits except on the outer level
rather
> than while. Probably the reason that it results in syntax error.
>
> while binAliveMarker:
>   try:
>     if binWannaStartAgainLater:
>       time.sleep(1)
>       continue
>     work code ...
>   except:
>     pass
>
> Any suggestions to make it work with continue (or an alternative) ? Apart
> from removing continue completely by making the work code inside an else ?
>
> Thanks,
>
> Sandipan
>
The documentation states that the continue syntax error is due to "laziness"
on the part of the implementors, though they seem to keep pretty busy to me.
You can work around this with:

class Continue:
    pass

while binAliveMarker:
  try:
    if binWannaStartAgainLater:
      time.sleep(1)
      raise Continue
    work code ...
  except Continue:
    continue

You could maybe leave the "pass" you had in the except rather than changing
it to continue, but it's never a good idea to include non-selective except
clauses: they catch KeyboardInterrupt, among other nasties you probably
really want to see.

[Just passing along a wrinkle somebody else taught me...]

regards
 Steve





More information about the Python-list mailing list