Stop if a loop is entering the shutdown mode while sleeping in with_period_of method