Home > Mobile >  Restart Python Code after restarting the server
Restart Python Code after restarting the server

Time:09-30

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!

CodePudding user response:

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>

CodePudding user response:

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
  • Related