Answers for "how to keep a python script running"

1

python dont exit script after print

input("Press enter to exit ;)")
Posted by: Guest on October-26-2020
0

always running python script

# in python, you should make a while(True) over the script
flag = True
while(flag):
  # Your awesome script goes here
	print("I'm running forever")
    # flag is there to have an exit option if needed
    flag = flase if statement == True else True

    
 
""" Now we need to make changes in system level """  
# In Windows #
# Use built-in program "Task-Scheduler"
- Create Task 
- In 'Triggers' tab add new trigger and selecet 'At startup'
- In 'Actions' tab add new action and write the command as you would write it in cmd (use absoulute path)
press OK and you DONE!

# In Ubuntu #
Create file 'foo.service' inside '/etc/systemmd/system'
and write inside 
"""
[Unit]
After=network.target
Description=bot

[Service]
Type=simple

ExecStart=/bin/bash -c 'python3 /home/ubuntu/Path/To/Directory/main.py'

Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target
"""

then in terminal run
sudo systemctl enable foo.service
sudo systemctl start foo.service 
Done!
Posted by: Guest on August-04-2021

Code answers related to "how to keep a python script running"

Python Answers by Framework

Browse Popular Code Answers by Language