How do I restart a Python service from within another file?

Viewed 27

I am trying to add some limited functionality to an existing project. Right now, it lives in Docker and has Python files run by docker-compose.yaml with various arguments, like this:

  init:
build: ./app
depends_on:
  - redisedge
command: ['init.py', '--url', 'redis://redisedge:6379']

One of these files has a Flask server, and I'm trying to add some rudimentary functionality without rewriting the whole thing. I'd like to add a POST route and, based on the parameters, rerun the init.py file with different args. Obviously, if the file is still running, this will cause issues, so I'd like to kill the process if it's running. Is there a good way to do this?

0 Answers
Related