def RepeatTimer(interval, function, iterations=0, *args, **kwargs):
  """Repeating timer. Returns a thread id."""

  def __repeat_timer(interval, function, iterations, args, kwargs):
    """Inner function, run in background thread."""
    count = 0
    while iterations <= 0 or count < iterations:
      sleep(interval)
      function(*args, **kwargs)
      count += 1

  return start_new_thread(__repeat_timer, (interval, function, iterations, args, kwargs))
Repeating timer. Returns a thread id.