python dont exit script after print
input("Press enter to exit ;)")
python dont exit script after print
input("Press enter to exit ;)")
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!
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us