code: def installStatsLoop(statsFile, statsDelay):
    
  
    def dumpStats():
      """Actual stats dump function."""
      scales.dumpStatsTo(statsFile)
      reactor.callLater(statsDelay, dumpStats)
  
    def startStats():
      """Starts the stats dump in "statsDelay" seconds."""
      reactor.callLater(statsDelay, dumpStats)
  
    reactor.callWhenRunning(startStats)
docs: Installs an interval loop that dumps stats to a file.