Re: better scheduler with correct sleep times



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.
.



Relevant Pages

  • Re: Single producer, "one-shot" work queue implementation, no lock on queue.
    ... usec for just calling execute() directly). ... overhead that's closer to 5nsec than 5usec. ... where there's only a single item in the queue. ... virtual void Execute() = 0; ...
    (comp.programming.threads)
  • Re: Do I need a RTOS?
    ... place, everything is empty ... ... the queue and requesting that I always keep some task in the queue. ... It is there that I call the execute function, over and over, pumping ... timer event, of course. ...
    (comp.arch.embedded)
  • Re: VB6 (formless) Timer class
    ... What you need to be concerned about is the thread used to execute ... other processing in your application grinds to a halt until that routine has ended. ... That includes the code you want responding to incoming calls. ... If the 'queue' response is acceptable to you, why not build it as a queue, ...
    (microsoft.public.vb.general.discussion)
  • Re: collecting results in threading app
    ... but execute one at the time'. ... Could a Queue help me there? ... You can take a look at papyros, a small package I wrote for hiding ... # some exception was raised when executing this job ...
    (comp.lang.python)
  • Re: Do I need a RTOS?
    ... Avail slots are by nature empty correct? ... in the avail queue, as I earlier defined them to be. ... head-pointers are equal to each other, the avail-queue is full and the ... decide to execute them is another issue. ...
    (comp.arch.embedded)