Monday, August 22, 2011

Simple job scheduling with Gevent

There are times when we need to run a function at repeated intervals. If we are lucky to already be using Gevent, these two lines make for a neat function to do that.

def schedule(delay, func, *args, **kw_args):
    gevent.spawn_later(0, func, *args, **kw_args)
    gevent.spawn_later(delay, schedule, delay, func, *args, **kw_args)

The idea is we let Gevent schedule the schedule() function in its event loop. This is like a (flat) tail-recursion call.

If we are not using Gevent, however, the package apscheduler is an advanced job scheduler similar Java Quartz and worth a serious look.

1 comment:

  1. Great! This is awesome Blog. By the help of this Blog I came to know about Job Scheduling . Thanks for providing me this type of information.