Jamiu S.
Jamiu S.

Reputation: 5721

How to keep a 30 day schedule script running with schedule

How do I close the terminal but keep a scheduled script running? It works for seconds, minutes with the terminal opened but terminates when the terminal is closed. Is there a way of working around it?

from schedule import every, repeat, run_pending
import time

@repeat(every(30).days.at("11:30"))
def auto_run_task():
    """Auto run task in every 30days to update CSV files."""
    print("Auto run task activated.")
    update_csv_file()
    print("file updated successfully")

while True:
    run_pending()
    time.sleep(1)

Upvotes: 0

Views: 136

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54718

Assuming you are on Linux, do nohup python myscript.py &. The purpose of the nohup command is to make the script a daemon so it detaches from the terminal.

Upvotes: 1

Related Questions