파이썬 APScheduler 실행해보기

728x90

https://velog.io/@jw3418/python%EC%9C%BC%EB%A1%9C-daemon-scheduler-%EA%B5%AC%ED%98%84

 

python으로 daemon scheduler 구현

데이터 자동 추가를 위해 linux crontab을 이용하려 했는데, 실행하고자 하는 crawling.py 파일에 외부 라이브러리가 많아서 그런지 (crontab 파일에 따로 library path를 추가해야 할듯?) crontab이 매달 실행

velog.io

참고 블로그

 

def job_function():
    subprocess.run(args=[sys.executable, "./main.py"])

sched = BackgroundScheduler(timezone='Asia/Seoul')

# interval형식 5초마다 실행
job = sched.add_job(job_function, 'interval', seconds=5)
sched.start()

while True:
    print("running")
    time.sleep(1)
def print_hi(name):
    print(f'Hi, {name}')  # 중단점을 전환하려면 Ctrl+F8을(를) 누릅니다.


# 스크립트를 실행하려면 여백의 녹색 버튼을 누릅니다.
if __name__ == '__main__':
    print_hi('Hello')

running

running

running

running

running

Hi Hello

 

https://apscheduler.readthedocs.io/en/3.x/modules/triggers/cron.html

 

apscheduler.triggers.cron — APScheduler 3.10.4.post1 documentation

Introduction This is the most powerful of the built-in triggers in APScheduler. You can specify a variety of different expressions on each field, and when determining the next execution time, it finds the earliest possible time that satisfies the condition

apscheduler.readthedocs.io

 

반응형