Python 7.0pl5 Benutzerhandbuch

Seite von 124
Event Framework
30
The member function for setting an alarm is "
setAlarm()
" and that for starting a timer is "
start-
Timer()
". The first argument is the callback function, the second argument is the absolute or relative
time and the third argument is an optional identifier for that alarm or timer. Scheduling an alarm or
timer with an identifier matching that of an alarm or timer which hasn’t yet expired will cause that un-
expired alarm or timer to be cancelled.
Both types of events are one off events, with the registration being cancelled once the callback has been
executed. The identifier may also be used to cancel an alarm or timer before it expires. To cancel an
alarm use "
cancelAlarm()
" and to cancel a timer use "
cancelTimer()
". To cancel all pending
alarms use "
cancelAllAlarms()
" and to cancel all pending timers use "
cancelAllTim-
ers()
". If an identifier is not excplicitly provided, an internal identifier will be automatically created
with it being returned as the result of the function being called to schedule the callback.
Recurring Actions
A recurring action is where a job is run at regular intervals. Precisely when the callback function asso-
ciated with a job is executed is determined by a specification of the form used by the UNIX cron utility.
The specification consists of five fields each separated by white space. The fields specify:
• minute (0-59),
• hour (0-23),
• day of the month (1-31),
• month of the year (1-12),
• day of the week (0-6 with 0=Sunday).
A field may be an asterisk "
*
", which always stands for "
first-last
". Ranges of numbers are al-
lowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For exam-
ple,
8-11
for an "hours" entry specifies execution at hours
8
,
9
,
10
and
11
.
Lists are allowed. A list is a set of numbers (or ranges) separated by commas. For example,
"
1,2,5,9
" and "
0-4,8-12
". Step values can be used in conjunction with ranges. Following a range
with "
/number
" specifies skips of the number’s value through the range. For example, "
0-23/2
"
can be used in the hours field to specify the callback function be executed every other hour. Steps are
also permitted after an asterisk, so if you want to say "every two hours", just use "
*/2
".
Names can also be used for the "month" and "day of week" fields. Use the first three letters of the par-
ticular day or month (lower case, or first letter only uppercase).
The day that a callback function is to be executed can be specified by two fields, day of month and day
of week. If both fields are restricted (ie., aren’t "
*
"), the callback function will be executed when either
field matches the current time. For example, "
30 4 1,15 * 5
" would cause the callback function
to be executed at 4:30 am on the 1st and 15th of each month, plus every Friday.
To schedule this type of job, the "
scheduleAction()
" function is used except that instead of spec-
ifying the job type as the second argument, the specification string should be used.