Linux - Check if python script is running in screen and run if not [closed]

2024/10/5 14:48:55

I am using "screen" to run a number of python scripts in AWS (linux build). One of those scripts will sometimes fail, for one reason or another. I would like to write either a) a python script or b) some kind of linux command line script to watch what python scripts are running, and if the target 'script.py' its not running then to rerun it.

For example:

import time
while(True):if script.py is running:time.sleep(5)else:open new linux screenpython3 script.pydetach screen

I'm sorry for this being vague, I never learned command line stuff, and I use it once in a blue moon. Screen took me a day to figure out how to use..

Thanks so much

Answer

ensure that flaky script keeps running

Your proposed approach could be made to work. But a nanny script would be much simpler. Call it e.g. nanny.sh.

#! /usr/bin/env bashwhile true
doscript.pysleep 1  # pause, so if script.py immediately dies we don't burn a core
done

Now we have replaced your "sometimes we randomly find script.py no longer running" situation with one where we're confident that the nanny is always running.

Diagnosing / fixing script.py is left as an exercise for the reader. Fortunately it now is a less urgent matter.

https://en.xdnf.cn/q/120271.html

Related Q&A

Making Phonebook in python : i want to get this screen by fixing my current code

I made my code like below....But as i input the data such as spam & number, previous data is deleted.So id like to make multiple value in one key... (i think using list is kinda good method)For exa…

Adding enemies to a pygame platformer

Im new to pygame and trying to make a platformer game thats based on this tutorial: http://programarcadegames.com/python_examples/show_file.php?file=platform_scroller.pyI cant quite figure out how to …

Tips for cleaning up a challenges answer? Weighted Sum of Digits [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.Improve…

Get a variable as filename from python script and use it in a batch script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 5 years ago.Improve…

Python 3.x AttributeError: NoneType object has no attribute groupdict

Being a beginner in python I might be missing out on some kind of basics. But I was going through one of the codes from a project and happened to face this :AttributeError: NoneType object has no attri…

importing images from local folder instead of using Keras/Tensorflow dataset

Hi Can someone please help me to change this code so that it wont get data from keras mnist. instead it will be getting data from local folder. where do i need to make changes in it. and where in this …

why I have negative date by subtraction of two column?

Im trying to create a column his values is the subtraction of two column but I found strange values:Patient["Waiting"] = Patient["Appointment"] - Patient["Scheduled"]Sched…

Python 3: AttributeError: int object has no attribute choice [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Scraping web pages with Python vs PHP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…