Unable to get python app running from a remote and close connection

Posted July 2, 2021 300 views
PythonDigitalOcean Droplets

I have a bitbucket pipeline file bitbucket-pipelines.yml which executes the file on my DO droplet each time a new commit is made to the main branch.

On DO, in turn calls which performs a set of actions:

  1. If it exists, kill the existing process
  2. Change to the directory containing the repo
  3. Pull from the repo
  4. Change to the directory containing
  5. Execute python3

It’s at this last step that my bitbucket pipeline will continue executing (consuming all my build minutes).

Is there any way that I can run the file and exiting the session whilst still allowing it to run?

I’ve attempted using nohupand &as well as exit. Neither result in a state where the pipeline disconnects from the DO droplet and stops and the application is running on the droplet.


image: atlassian/default-image:latest

      - step:
              - cat ./ | ssh -tt
              - echo "Deploy step finished"

echo "Deploy Script Started"
echo "Deploy script finished execution"

## Kills the current process which is restarted later
kill -9 $(pgrep -f

## And change to directory containing the repo
cd eg-api

## Pull from the repo
export GIT_SSH_COMMAND="ssh -i ~/.ssh/"
GIT_SSH_COMMAND="ssh -v" git pull

## Change to directory containing the python file to execute
cd refgator-api
python3 &

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.

Submit an Answer
1 answer

Hi there @christianmacedo,

I could suggest using Supervisor as a more robust solution. You can follow the steps on how to install Supervisor here:

You could again put the python3 and then specify the path to the script in the supervisor config file as described in the tutorial:


Hope that this helps!

Here's our tutorial on installing and managing Supervisor on Ubuntu and Debian.