Re: better scheduler with correct sleep times

2008-10-23 Thread sokol
On Oct 22, 2:28 am, greg <[EMAIL PROTECTED]> wrote: > sokol wrote: > > Also, the > > scheduler runs inside a loop. How do you suppose to > > run other code while the loop is executing? > > The sleep function could be doing a select with a > timeout on some other source of events, such as a > socket

Re: better scheduler with correct sleep times

2008-10-21 Thread Gabriel Genellina
On 2008-10-21, sokol <[EMAIL PROTECTED]> wrote: > On Oct 21, 2:19 am, greg <[EMAIL PROTECTED]> 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 >>

Re: better scheduler with correct sleep times

2008-10-21 Thread greg
sokol wrote: Also, the scheduler runs inside a loop. How do you suppose to run other code while the loop is executing? The sleep function could be doing a select with a timeout on some other source of events, such as a socket or a gui input event stream. One possible response to such an event i

Re: better scheduler with correct sleep times

2008-10-21 Thread Carl Banks
On Oct 21, 4:58 am, sokol <[EMAIL PROTECTED]> wrote: > On Oct 21, 2:19 am, greg <[EMAIL PROTECTED]> 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 multithreadi

Re: better scheduler with correct sleep times

2008-10-21 Thread sokol
On Oct 21, 2:19 am, greg <[EMAIL PROTECTED]> 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 o

Re: better scheduler with correct sleep times

2008-10-20 Thread greg
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 eve

Re: better scheduler with correct sleep times

2008-10-20 Thread sokol
On Oct 20, 1:50 pm, Lie <[EMAIL PROTECTED]> wrote: > On Oct 19, 4:01 am, sokol <[EMAIL PROTECTED]> 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 st

Re: better scheduler with correct sleep times

2008-10-20 Thread Lie
On Oct 19, 4:01 am, sokol <[EMAIL PROTECTED]> 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 ar

Re: better scheduler with correct sleep times

2008-10-20 Thread Lie
On Oct 19, 4:01 am, sokol <[EMAIL PROTECTED]> 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 ar

Re: better scheduler with correct sleep times

2008-10-19 Thread James Mills
On Mon, Oct 20, 2008 at 5:31 AM, sokol <[EMAIL PROTECTED]> wrote: > >> from circuits.core import Manager, Component, Event, listener >> from circuits.timers import Timer > > what is circuits? If you're interested: An event framework with a focus on Component architectures. It can be downloaded cu

Re: better scheduler with correct sleep times

2008-10-19 Thread Scott David Daniels
sokol wrote: ... I see what you did there. You are keeping the queue empty so you get notified for free, while I introduced a new threading Condition to detect insertions. All that is missing in your version is to put back all pending tasks when somebody sends the stop (None) request. Shouldn't

Re: better scheduler with correct sleep times

2008-10-19 Thread sokol
On Oct 19, 6:25 pm, Scott David Daniels <[EMAIL PROTECTED]> wrote: > qvx wrote: > > I need a scheduler which can delay execution of a > > function for certain period of time. > > My attempt was something like this:  ... <<>> > > Is there a better way or some library that does that? > > The trick is

Re: better scheduler with correct sleep times

2008-10-19 Thread sokol
> from circuits.core import Manager, Component, Event, listener > from circuits.timers import Timer what is circuits? -- http://mail.python.org/mailman/listinfo/python-list

Re: better scheduler with correct sleep times

2008-10-19 Thread Scott David Daniels
Scott David Daniels wrote: def time_server(commands): '''Process all scheduled operations that arrive on queue commands''' ... queue = Queue.Queue() thread.thread.start_new_thread(queue) > queue.put((time.time() + dt, callable, args, {})) > ... And of course of the three lines that wer

Re: better scheduler with correct sleep times

2008-10-19 Thread Scott David Daniels
qvx wrote: I need a scheduler which can delay execution of a function for certain period of time. My attempt was something like this: ... <<>> Is there a better way or some library that does that? The trick is to use Queue's timeout argument to interrupt your sleep when new requests come in.

Re: better scheduler with correct sleep times

2008-10-18 Thread James Mills
On Sat, Oct 18, 2008 at 10:09 PM, qvx <[EMAIL PROTECTED]> wrote: [ ... ] > Is there a better way or some library that does that? How about this ? $ ./timerexamples.py Time: 1224375945.336958 Timer 2 fired at: 1224375945.840600 Timer 1 fired at: 1224375955.336889 #!/usr/bin/env python import

Re: better scheduler with correct sleep times

2008-10-18 Thread sokol
> > 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

Re: better scheduler with correct sleep times

2008-10-18 Thread Chris Rebert
On Sat, Oct 18, 2008 at 5:09 AM, qvx <[EMAIL PROTECTED]> wrote: > I need a scheduler which can delay execution of a > function for certain period of time. > My attempt was something like this: > [code snipped] > > But then I came up with the following case: > > 1. I call delay with delay_sec = 10 >

better scheduler with correct sleep times

2008-10-18 Thread qvx
I need a scheduler which can delay execution of a function for certain period of time. My attempt was something like this: def delay(self, func, arg, delay_sec=0): fire_at = wallclock() + delay_sec self.queue.put((fire_at, func, arg)) def runner(self): while self.a