Re: Idle handling questions
Re: Idle handling questions
- Subject: Re: Idle handling questions
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 15 Nov 2001 17:55:36 -0500
on 11/14/01 4:39 PM, Connor W. Anderson at email@hidden wrote:
>
When
>
this script is run as a cron job (the old Classic Cron implementation, great
>
stuff!) it generates an AppleEven timeout error either in the recalcToday
>
script or in the openAdTrackerDBs script which has a very similar idle
>
handling routine.
The Idle handler and timeout errors have nothing to do with one another.
I explain the difference somewhere on my web site -- probably in the "Hurry
Up and Wait" article in the "Tips" chapter. Basically, a timeout error
occurs when AppleScript thinks it has waited too long for an event that was
sent to an application to generate a response. I forget whether the default
is 30 seconds or 60 seconds. You can avoid such a timeout error by enclosing
the offending statements in a 'with timeout' block, specifying any shorter
or longer timeout period you like. If the application responds within the
specified timeout period, you won't get an error. Set it to millions of
seconds, and AppleScript will give the application millions of seconds to
respond. Of course, if the application responds more quickly, AppleScript
will be happy and move on.
The Idle handler serves a completely different purpose. When a stay-open
script application containing an Idle handler has nothing to do (that is,
its Run or Open handler has finished running), it will sit there doing
nothing (that is, letting other processes on the machine fully utilize the
processor) until the specified Idle interval has expired, at which time it
will call the Idle handler -- and then go back into hibernation for a while.
It is entirely possible for statements within an Idle handler -- or outside
-- to generate timeout errors, which have nothing to do with the script's
Idle handler.
So, to cure your problem, you have to isolate the statement or statements
that are not getting a response from an application quickly enough (that is,
within the 30- or 60-second default timeout period), then enclose them in a
With Timeout block giving the application more time. How much more time it
needs is a matter for experimentation -- if you care. You can start by
giving it, say, an hour's worth of seconds. It doesn't really matter if you
set it to a very, very long time -- say, a week or a month -- if you know
the application is actually capable of responding to the script. The only
reason for the timeout error feature to exist in AppleScript is to let you
know whether an application hasn't responded within a time period that you
know is long enough for it to respond -- in other words, to let you know
that an unexpected error must have occurred, such as the application's
having frozen.
Isolating the statements that are timing out can be tedious. You can try
putting Display Dialog statements at strategic places in order to narrow the
possibilities.
A good way to write a script that has generated a timeout error is to give
it a very long timeout period at first, while you're revising and testing it
to make sure the script is written correctly. Then, once you know it's
working correctly, throttle down the timeout period to whatever value you
think must in all likelihood indicate that something has gone wrong with the
target application. It doesn't have to be the shortest time that doesn't
generate an error. It can be a much longer period, one that best serves your
administrative needs. Say, 5 minutes, if your midnight administrator always
takes a 6-minute coffee break after firing up the script. Or 30 minutes if
you know it usually takes about 25 minutes to run the backup.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont