nip.timing.timeables.register_timeable

nip.timing.timeables.register_timeable#

nip.timing.timeables.register_timeable(_timeable: type[Timeable] | Callable | None = None, *, name: str | None = None) Callable | type[Timeable][source]#

Register a timeable.

If a callable is given, a subclass of Timeable is created with the callable as the run method.

Parameters:
  • timeable (Timeable | callable) – The timeable to register. Can a subclass of Timeable or a callable.

  • name (str, optional) – The name to register the timeable under. If not given, the name of the timeable is used.

Returns:

Timeable – The timeable that was registered. If a callable was given, the subclass of Timeable that was created is returned.

Examples

Register a subclass of Timeable: >>> @register_timeable(name=”my_timeable”) … class MyTimeable(Timeable): … def __init__(self): … pass … def run(self, profiler): … pass

Register a callable: >>> @register_timeable … def my_timeable(profiler): … pass