delay_manager

class mpf.core.delays.DelayManager(registry)

Bases: mpf.core.mpf_controller.MpfController

Handles delays for one object.

Methods & Attributes

The delay_manager has the following methods & attributes available. Note that methods & attributes inherited from the base class are not included here.

add(ms, callback, name=None, **kwargs)

Add a delay.

Parameters:
  • ms -- Int of the number of milliseconds you want this delay to be for. Note that the resolution of this time is based on your machine's tick rate. The callback will be called on the first machine tick after the delay time has expired. For example, if you have a machine tick rate of 30Hz, that's 33.33ms per tick. So if you set a delay for 40ms, the actual delay will be 66.66ms since that's the next tick time after the delay ends.
  • callback -- The method that is called when this delay ends.
  • name -- String name of this delay. This name is arbitrary and only used to identify the delay later if you want to remove or change it. If you don't provide it, a UUID4 name will be created.
  • **kwargs -- Any other (optional) kwarg pairs you pass will be passed along as kwargs to the callback method.
Returns:

String name of the delay which you can use to remove it later.

add_if_doesnt_exist(ms, callback, name, **kwargs)

Add a delay only if a delay with that name doesn't exist already.

Parameters:
  • ms -- Int of the number of milliseconds you want this delay to be for. Note that the resolution of this time is based on your machine's tick rate. The callback will be called on the first machine tick after the delay time has expired. For example, if you have a machine tick rate of 30Hz, that's 33.33ms per tick. So if you set a delay for 40ms, the actual delay will be 66.66ms since that's the next tick time after the delay ends.
  • callback -- The method that is called when this delay ends.
  • name -- String name of this delay. This name is arbitrary and only used to identify the delay later if you want to remove or change it.
  • **kwargs -- Any other (optional) kwarg pairs you pass will be passed along as kwargs to the callback method.
Returns:

String name of the delay which you can use to remove it later.

check(delay)

Check to see if a delay exists.

Parameters:delay -- A string of the delay you're checking for.

Returns: The delay object if it exists, or None if not.

clear()

Remove (clear) all the delays associated with this DelayManager.

configure_logging(logger, console_level='basic', file_level='basic')

Configure the logging for the module this class is mixed into.

Parameters:
  • logger -- The string name of the logger to use
  • console_level -- The level of logging for the console. Valid options are "none", "basic", or "full".
  • file_level -- The level of logging for the console. Valid options are "none", "basic", or "full".
debug_log(msg, *args, **kwargs)

Log a message at the debug level.

Note that whether this message shows up in the console or log file is controlled by the settings used with configure_logging().

error_log(msg, *args, **kwargs)

Log a message at the error level.

These messages will always be shown in the console and the log file.

info_log(msg, *args, **kwargs)

Log a message at the info level.

Whether this message shows up in the console or log file is controlled by the settings used with configure_logging().

remove(name)

Remove a delay by name.

I.e. prevents the callback from being fired and cancels the delay.

Parameters:name -- String name of the delay you want to remove. If there is no delay with this name, that's ok. Nothing happens.
reset(ms, callback, name, **kwargs)

Reset a delay, first deleting the old one (if it exists) and then adding new delay with the new settings.

Parameters:as add() (same) --
run_now(name)

Run a delay callback now instead of waiting until its time comes.

This will cancel the future running of the delay callback.

Parameters:name -- Name of the delay to run. If this name is not an active delay, that's fine. Nothing happens.
warning_log(msg, *args, **kwargs)

Log a message at the warning level.

These messages will always be shown in the console and the log file.