SimpleCRON class

class scron.week.SimpleCRON(*args, **kwargs)[source]
add(callback_name, callback, seconds=-1, minutes=-1, hours=-1, weekdays=-1, removable=True)[source]

Adds an entry to the current queue.

After adding a callback, the next call is recalculated.

Parameters
  • callback_name – callback name ID

  • callback – callable

  • seconds – 0-59 or list(second, …), default: SimpleCRON.WILDCARD_VALUE

  • minutes – 0-59 or list(minutes, …), default: SimpleCRON.WILDCARD_VALUE

  • hours – 0-23 or list(hours, …), default: SimpleCRON.WILDCARD_VALUE

  • weekdays – 0-6 or list(days, …) 0=monday,6=sunday, default: SimpleCRON.WILDCARD_VALUE

  • removable – boolean if false, then the entry cannot normally be deleted

Returns

None

callback_exists(callback_name)

Checking if a callback exists

Parameters

callback_name

Returns

boolean

get_current_pointer(_localtime=None)[source]

Returns the pointer generated from the current date.

Returns

tuple(weekday, hour, minute, second)

get_next_pointer(weekday, hour, minute, second)[source]

Returns the nearest next pointer for the counter.

Parameters
  • weekday – 0-6, 0=monday,6=sunday

  • hour – 0-23

  • minute – 0-59

  • second – 0-59

Returns

tuple(weekday, hour, minute, second)

list(_time_table_node=None, _prev_data=None)

Returns the generator containing full and ordered information about all steps.

Parameters
  • _time_table_node – internal variable

  • _prev_data – internal variable

Returns

next_step(*last_time_pointer)[source]

Returns the generated function for the timer.

Parameters

last_time_pointer – last call pointer

Returns

function(timer_instance)

remove(callback_name, force=False, _lock=True)

Removes from the counters a callback that occurs under ID callback_name.

Recalculates the nearest callback to call.

Parameters
  • force – force removal of the callback.

  • callback_name – callback name

remove_all(force=False)

Removes all calls from the counters.

Parameters

force – force removal of the callback.

Returns

run(timer_id=1)

Initiates a list of tasks and reserves one hardware timer.

Warning: “OSError: 261” - error means a problem with the hardware timer. Try to set another timer ID. See MicroPython documentation for machine.Timer.

Parameters

timer_id – hardware timer ID

run_callbacks(weekday, hour, minute, second)[source]

Runs all callbacks for a given pointer.

Parameters
  • weekday – 0-6, 0=monday,6=sunday

  • hour – 0-23

  • minute – 0-59

  • second – 0-59

Callback decorators

class scron.decorators.call_counter(callback)[source]

Decorator counts the number of callback calls.

The number of calls is stored in memory[call_counter.ID].

Parameters

callback

Returns

scron.decorators.debug_call(callback)[source]

The decorator displays information about the current call

Parameters

callback

Returns

scron.decorators.run_times(times)[source]

The decorator determines how many times the given callback can be started.

Parameters

times – number of start-ups

Returns

scron.decorators.successfully_run_times(times)[source]

The decorator determines how many times the given callback can be started.

Launching a task is considered correct only if the callback returns True.

Parameters

times – number of start-ups

Returns

class scron.decorators.time_since_last_call(callback)[source]

Measures the time since the last call.

Stores the result in memory[time_since_last_call.ID] == tuple(<seconds>, <mili_seconds>)

Parameters

callback

Returns