crython/tab

Contains functionality for executing jobs (python functions) from cron expressions.

class crython.tab.CronTab(*args, **kwargs)

Background thread responsible for executing background jobs.

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

register(name, job)

Register the given name and function.

Parameters
  • name – Name of the registered job. Note: This should be unique.

  • job – Callable decorated with job() to execute.

Returns

None.

deregister(name)

De-register the job that was registered with the given name.

Parameters

name – Name of the job to remove.

Returns

None.

stop()

Stop this background thread from executing any more jobs.

Returns

None.

run()

Background function that processes all registered jobs and invokes them based on their context and expression.

crython.tab.default_tab

The default, global tab instance that is created on import. This is the instance that will be used unless the job() caller overrides it.

crython.tab.start()

Start the default, global CronTab instance.

crython.tab.stop()

Stop the default, global CronTab instance.

This informs the background thread to stop processing new jobs but does not wait for it to finish completing its current ones. If the caller wishes to wait for the thread to stop completely, it should call join().