Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python keep program running after crash

from subprocess import run
from time import sleep

# Path and name to the script you are trying to start
file_path = "test.py" 

restart_timer = 2
def start_script():
    try:
        # Make sure 'python' command is available
        run("python "+file_path, check=True) 
    except:
        # Script crashed, lets restart it!
        handle_crash()

def handle_crash():
    sleep(restart_timer)  # Restarts the script after 2 seconds
    start_script()

start_script()
Comment

PREVIOUS NEXT
Code Example
Python :: Python Windows Toggle Caps_Lock 
Python :: truncated float python 
Python :: Compute p-value 
Python :: string letters only 
Python :: Python RegEx Split – re.split() Syntax 
Python :: ridge regression alpha values with cross validation score plot 
Python :: Book.__init__() missing 5 required positional arguments 
Python :: ABA Alphabet pyramid 
Python :: how to open local software using python 
Python :: print two values using f string 
Python :: set DJANGO_SETTINGS_MODULE=mysite.settings django-admin 
Python :: how to add strings with entry in tkinter 
Python :: python SynC 
Python :: simulieren mit python 
Python :: Understand the most appropriate graph to use for your dataset visualization 
Python :: buscar elemento en lista python 
Python :: a list of available font in figlet in python 
Python :: newton backward interpolation python code 
Python :: extract arabic text from image python 
Python :: extract metadata from xml tei file python 
Python :: odoo.py odoo 14 
Python :: python sum whole matrix comand 
Python :: add values to add value in a matplotlib image 
Python :: numpy documentation realpython 
Python :: two legend left and right x asix matplotlib 
Python :: inject dynamic value into string python 
Python :: morphological filter example python 
Python :: pass in 2 numbers, A and B. You should create a list with A rows and B columns, then populate each cell 
Python :: python slice second element of list of lists 
Python :: couple legend from twin axes python 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =