Question

Python scripts stops when I exit the Console

Hi all,

I have a Droplet with the following specifications:

4 GB Memory / 50 GB Disk / AMS3 - Ubuntu 20.04 (LTS) x64

When I access the Console with my non-root username I run the python script using

python3 scheduler.py

The script should run all day but as soon as I exit the Console (or Terminal), the scripts stops. I know this because there is no new data added to my database. The same script works fine when it runs on my local computer. What am I doing wrong or which settings should I change?

Thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
May 21, 2022
Accepted Answer

Hi @hjmeulenbelt,

How do you run the Script? Do you just run python3 scheduler.py in your Terminal, do you add a Screen session or use PM2? If you are not, there are a couple of ways to go.

The first and easiest to go is, to open a Screen session in your Terminal to start the scrip and then detach from that Screen session. Take a look at the following tutorial:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-screen-on-an-ubuntu-cloud-server

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel