Re: better scheduler with correct sleep times
- From: Lie <Lie.1296@xxxxxxxxx>
- Date: Mon, 20 Oct 2008 04:47:49 -0700 (PDT)
On Oct 19, 4:01 am, sokol <tvrtko.sokolov...@xxxxxxxxx> wrote:
I started googling for scheduler and found one in standard library
but ih has the same code as mine (it calls the functions in the
right order and my doesn't, but it still waits too long).
The other schedulers from web are dealing with
repeating tasks and such.
I believe you're looking for the 'sched' module:http://www.python.org/doc/2.5.2/lib/module-sched.html
The sched module behaves just like mine version because
it uses almost the same code. My observations include the
sched module as well. Check it's source code. It is flawed:
it calls the sleep method and while it sleeps (presumably
for a long time) all newly scheduled events are on hold.
See my example in original post.
My code solves this problem (or so it looks to me right now).
The trick to your problem is the heart of any event-driven
programming: Event Queue. There will always be a mainloop, which is a
method that would check the queue for new events and execute the
appropriate callbacks for each event. For a Timer object, it will be
an event that returns a callback that simply reinserts itself to the
the queue until "the time" has arrived. When the time has arrived, it
will execute the function you've given before.
Note that there is no need to use threading here.
.
- References:
- better scheduler with correct sleep times
- From: qvx
- Re: better scheduler with correct sleep times
- From: Chris Rebert
- Re: better scheduler with correct sleep times
- From: sokol
- better scheduler with correct sleep times
- Prev by Date: Re: dumping in destructor
- Next by Date: Re: indentation
- Previous by thread: Re: better scheduler with correct sleep times
- Next by thread: Re: better scheduler with correct sleep times
- Index(es):
Relevant Pages
|