简体   繁体   中英

Run python script in an range of hours

can i run my script in an range of hours? For example: I would like to execute my script every day from 6am to 12 pm. At 12:01 pm i would like to kill the process

Thanks

PS: My script is hosted on heroku

TLDR; use cron in linux- make your python script executable then config your cron to run how ever you want.

In windows you can use a scheduled task.

Abit of explanation about cron - It's basically a time-based job scheduler in Unix-like computer operating systems.

Follow the link below for full explanation on how to run python scripts with crons.

https://medium.com/@gavinwiener/how-to-schedule-a-python-script-cron-job-dea6cbf69f4e

Alternatively if the heroku is running all the time you can use BackgroundScheduler() from APScheduler

reference - Scheduling a function to run every hour on Flask

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM