Hi Terry,
> Way back in September I asked for help to understand the documentation
> for apscheduler. Help duly came and I got a program working to
> trigger functions to rung the bells every time an hour or a quarter
> hour arrived. This is what I ended up with:
>
> http://hadrian-way.co.uk/Misc/minsterbells_v04py
Bits of Python you might find useful...
There's an `elif', standing for `else if': if...elif...elif...else
You can return early from a function, avoiding a big else block and the
reader tracking that extra state.
if not opening_hours:
return # Do nothing.
Increment and decrement can use += and -=.
# Same as foo = foo + 3, but I don't need to check both are foo.
foo += 3
A for loop can run over a half-open interval.
for h in xrange(10, 22 + 1):
print h # 10 to 22 inclusive.
Logical operators include `and' and `or'.
opening_hours = hour >= 10 and (hour <= 17 or enable_late and hour <= 22)
> Unfortunately, since then, apscheduler has been updated
You might be able to fix apscheduler at a particular version somehow to
stop it breaking.
> I think that BackgroundScheduler looks the most likely candidate to do
> what I want.
Don't think so. You existing program did `sched.daemonic = False'
whereas the default is True for BackgroundScheduler. Since your program
wants to do nothing else once it's configured the scheduler other than
wait for jobs to be triggered, don't you want a plain old
BlockingScheduler: "A scheduler that runs in the foreground (start()
will block)".
> Can anyone help me to get the right syntax to replicate the old
> functionality
I've only had a quick look. The scheduler now needs importing from its
particular package.
< from apscheduler.scheduler import Scheduler
> from apscheduler.schedulers.blocking import BlockingScheduler
Instantiating it is different.
< sched = Scheduler()
< sched.daemonic = False
> sched = BlockingScheduler()
And you move the `sched.start()' to the end of the program, after you've
added all the jobs rather that just after the instantiation as it is
now.
Cheers, Ralph.
--
Next meeting: Bournemouth, Tuesday, 2017-02-07 20:00
Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/
New thread: mailto:[email protected] / CHECK IF YOU'RE REPLYING
Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR