def periodically_run( period, &block )
      raise ArgumentError, 'a runner already exists' unless @runner.nil?

      @runner = Thread.new do
        start = stop = Time.now.to_f
        loop do
          seconds = period - (stop-start)
          seconds = period if seconds <= 0
          sleep seconds

          start = Time.now.to_f
          break if Thread.current[:stop] == true
          if @mutex then @mutex.synchronize(&block)
          else block.call end
          stop = Time.now.to_f
        end
      end
    end
def periodically_run( period, &block )
      raise ArgumentError, 'a runner already exists' unless @runner.nil?

      @runner = Thread.new do
        start = stop = Time.now.to_f
        loop do
          seconds = period - (stop-start)
          seconds = period if seconds <= 0
          sleep seconds

          start = Time.now.to_f
          break if Thread.current[:stop] == true
          if @mutex then @mutex.synchronize(&block)
          else block.call end
          stop = Time.now.to_f
        end
      end
    end
Periodically execute the given _block_ at the given _period_. The
 tracker will be locked while the block is executing.

 This method is useful for logging statistics at given interval.

 Example

    periodically_run( 300 ) {
      logger = Logsly::Logging182::Logger['stats']
      tracker.each {|sampler| logger << sampler.to_s}
      tracker.reset
    }