better scheduler with correct sleep times
tvrtko.sokolovski at gmail.com
Tue Oct 21 10:58:16 CEST 2008
On Oct 21, 2:19 am, greg <g... at cosc.canterbury.ac.nz> wrote:
> sokol wrote:
> > What was a surprise to me was that python sched.py makes the same
> > mistake as I did in my first version.
> The sched module is *not* designed for multithreading. It
> assumes that the thread waiting for events is the only one
> putting events into the queue, so it's impossible for an
> event to get scheduled while in the midst of a sleep. It
> also doesn't take any measures to protect its data structures
> from concurrent access.
> The documentation could make this clearer, especially since
> it confusingly talks about "allowing other threads to run".
I find that hard to believe. Scheduler in single threaded
application is useless (well, you can correct me because
right now I can't come up with an example). Also, the
scheduler runs inside a loop. How do you suppose to
run other code while the loop is executing? Remember, all
you have is a single thread. The consequence of this is
that the only way to insert something new inside a queue
is by doing it from scheduled function. Furthermore,
if scheduler is single threaded, why does is
check if the top event has changed after sleep period?
What I can agree is that python sched as it is (not
designed for multithreading) is quite useless.
More information about the Python-list