신호생성 repo (24. 1. 5 ~).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

20 lines
691 B

import sched
import time
from datetime import datetime
# 스케줄러 객체 생성
scheduler = sched.scheduler(time.time, time.sleep)
def print_current_time(sc):
print("Current Time:", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
# 다음 실행을 위해 5초 후에 이 작업을 다시 예약
sc.enter(5, 1, print_current_time, (sc,))
if __name__ == "__main__":
# 현재 초(second)를 기준으로 다음 5초 배수 시각까지의 지연 시간 계산
now = datetime.now()
initial_delay = 5 - (now.second % 5)
# 초기 작업 예약
scheduler.enter(initial_delay, 1, print_current_time, (scheduler,))
# 스케줄러 실행
scheduler.run()