Author giampaolo.rodola
Recipients akuchling, djarb, facundobatista, forest, giampaolo.rodola, gvanrossum, intgr, j1m, jafo, josiahcarlson, kevinwatters, markb, mcdonc, pitrou, r.david.murray, stutzbach, tseaver
Date 2010-05-11.16:55:32
SpamBayes Score 0.0277757
Marked as misclassified No
Message-id <1273596935.73.0.967941041182.issue1641@psf.upfronthosting.co.za>
In-reply-to
Content
> Let the user leverage the existing scheduler API.  Cut out 
> scheduled_task and call_later, which just wraps the scheduler API.  
> The user can simply call scheduled_tasks.enter() or 
> scheduled_tasks.cancel().  It's one less API for them to learn and 
> one less for us to maintain.

I think a wrapper around sched.py is necessary.
Now that I wrote tests for it I realized its API is pretty rusty and old.


Adding a call:

scheduler = sched.scheduler(time.time, time.sleep)
scheduler.enter(10, 1, function, (arg,))

...vs:

asyncore.call_later(10, function, arg)


Cancelling a call:

scheduler = sched.scheduler(time.time, time.sleep)
event = scheduler.enter(10, 1, function, (arg,))
scheduler.cancel(event)

...vs:

event = asyncore.call_later(10, function, arg)
event.cancel()


Moreover, reset() and delay() methods are not implemented in sched.
By using call_later you can do:

event = asyncore.call_later(10, function, arg)
event.reset()
event.delay(10)

By using sched.py you'll have to recreate a new event from scratch (scheduler.cancel(event) -> calculate the new timeout, scheduler.enter(newtime, 1, function, (arg,)).

Other problems which comes to mind are: you can't easily know whether a call has already been cancelled, you can't manually fire it before the timeout has expired and I'm not even sure whether it's possible to pass kwargs to enter(), which is crucial (with call_later you can do it like this: asyncore.call_later(10, function, x, y, z='foo')).
History
Date User Action Args
2010-05-11 16:55:37giampaolo.rodolasetrecipients: + giampaolo.rodola, gvanrossum, akuchling, facundobatista, jafo, josiahcarlson, tseaver, pitrou, forest, kevinwatters, djarb, stutzbach, markb, r.david.murray, intgr, mcdonc, j1m
2010-05-11 16:55:35giampaolo.rodolasetmessageid: <1273596935.73.0.967941041182.issue1641@psf.upfronthosting.co.za>
2010-05-11 16:55:33giampaolo.rodolalinkissue1641 messages
2010-05-11 16:55:32giampaolo.rodolacreate