Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep the Python script running continuously on a GCP VM

Recently, I developed a Python script that runs on a GCP VM. This script takes user input and generates the corresponding output based on that input.

When I attempted to run it on a GCP VM, it executed without any problems, and the script performed perfect. However, after a couple of hours, the script completely goes down.

Additionally, I used python anywhere to run the script. but, it has a resources limitation.

I generally run it like python3 script.py

like image 382
Nani Avatar asked Jun 12 '26 09:06

Nani


1 Answers

you can run a systemd job with it and use a timer to define when and and how often it should run. https://wiki.ubuntuusers.de/systemd/Timer_Units/

Well, with user input it makes it more complicate, but maybe you find you solution here: https://unix.stackexchange.com/questions/453998/systemd-connect-to-stdin-stdout-after-service-has-started

like image 196
ubuntujule Avatar answered Jun 13 '26 22:06

ubuntujule