vendredi 27 mars 2015

What's special about port 6000 on Mac OS?

Start your Mac. Take the base Flask app from the quickstart page, and change the port to 6000, which gives you the following:



from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello World!'

if __name__ == '__main__':
app.debug = True
app.run(port=6000)


Save this in a file named e.g. test.py. Then create a virtualenv, run pip install flask, and call test.py. Here is what you will see on the terminal:



* Running on http://0.0.0.0:6000/ (Press CTRL+C to quit)
* Restarting with stat


So Flask claims to have bound to port 6000. Now start a browser and navigate to localhost:6000. I was expecting to see the silly message Hello World, which is the case when I leave out the port argument to run, and navigate to localhost:5000. But here is what I see instead:


enter image description here


Now do Ctrl-C on the terminal, and stop the running process. Change the port to 6001, rerun the command. Hello World is back! How can this be? There are no other processes connecting to port 6000; lsof -i | grep 6000 returns 0 results, and if there were any processes, Flask would fail to bind to that port in the first place. Firewall is turned off.


Any ideas?





Aucun commentaire:

Enregistrer un commentaire