add sleep_next_period in while loop