997Flask – [Errno 48] Address already in use

Problem:

Stopping the flask server with ⌃-Z (CRTL-Z), instead of the correct ⌃-C (CRTL-C), results in the server still bound to port 5000:

OSError: [Errno 48] Address already in use

Problem: After Flask crash, the port can still be occupied.

Solution:

Check who is using port 5000

sudo lsof -i:5000
kill $PID
kill -9 $PID

Success:

[2]  + killed     flask run