[issue1641] asyncore delayed calls feature

Giampaolo Rodola' report at bugs.python.org
Tue May 11 18:55:35 CEST 2010


Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

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

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1641>
_______________________________________


More information about the Python-bugs-list mailing list