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

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.