Being able to develop stuff locally is certainly on of the points I love the most working with Azure and Python. Later, you can hyper-scale the shit out of your code, but you can also debug it first on your tiny machine.
if __name__ == '__main__':
# This code only runs when executing the script directly (not on App Service)
logging.info("Starting Flask app in local development mode")
socketio.run(app, host='0.0.0.0', port=5000, debug=True)
This piece of code is probably run a thousand times every day by a thousand developers. However, it was quite difficult to find an easy answer on google for this:
OSError: [Errno 48] Address already in use: ('0.0.0.0', 5000)
Easy to understand what it means, like port 5000 is in use already. WTF? Who is running something on my machine???
Of course, me. Another PyCharm window or something. But no, not this time. Strange. `netstat to the rescue 🙂 Well, not on macOS.
For whatever reason it cannot show you ports in LISTEN, at least that I could find. But how can we figure it out? lsof can help us here:
lsof -i :5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 650 trueal 10u IPv4 0xa162a6f756348686 0t0 TCP *:commplex-main (LISTEN)
ControlCe 650 trueal 11u IPv6 0x2c61017c47991be 0t0 TCP *:commplex-main (LISTEN)
WTF is a commplex? Another round of googling shows it belongs to AirPlay. So technically, ever developer on macOS should not be able to run the demo code?? So at least now you know, too, what is hogging your precious port 5000. You’re welcome.