I want to kill anything on a given port (i.e. 5000) prior to launching a flask application. Here is what I have so far:
In app.py:
if __name__ == "__main__":
os.system('./kill.sh')
app.run(host="0.0.0.0", debug=True)
In kill.sh:
lsof -ti:5000 | xargs kill -9
If I run kill.sh in terminal everything gets killed on port 5000. So I know that works. However when I run app.py
flask starts but THEN gets killed by kill.sh
. So it seems that os.system
is not waiting to finish before executing app.run
. How can I get it to wait?