简体   繁体   中英

Restart Python Code after restarting the server

I have a Python code running on Spyder on our server which needs to run constantly. However, from time to time our server breaks and it is restarted. Unfortunately, my code stops running as well and I need to restart Spyder and the code manually when opening it the next day.

Is there any way to restart the code automatically when the server is restarted?

Thank you a lot!

You can add as a crontab rule what you want to run after reboot.

You can use this line in crontab by using crontab -e command, if you use server running on Linux platform.

@reboot <your_python_file_path>

Simply utilize shell:startup and add your Python location + path there (or create a Batch script for it):

myprogram.bat :

python.exe main.py

Alternatively, if you don't have python location in your PATH env variable, utilize the full path:

myprogram.bat :

"C:\Program Files\Python39\python.exe" main.py

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