[PYTHON] Error in Flask OSError: [Errno 98] Address already in use

phenomenon

While creating a Flask application, I got the title error when I modified the module many times with the server running.

Error message

OSError: [Errno 98] Address already in use

It's still a message, but it seems that "I can't use the address I'm trying to use now because I'm already using it elsewhere." In such a case, search for the error message by guessing that the port is full.

As a result of the search, the following articles were hit. https://qiita.com/ringCurrent/items/2413c795372baa7b479d

The error numbers are different between "48" and "98", but it is probably an environmental difference, so I will implement the solution without worrying about it.

  1. Install the "lsof" command It seems that the port in use is checked with the lsof command, but it does not seem to be in the docker environment you are using.
(base) root@e8cf64ce12e9:/home/continuumio# lsof -i :5000
bash: lsof: command not found

Install quickly. (Use apt because OS is ubuntu)

(base) root@e8cf64ce12e9:/home/continuumio# apt install lsof
Reading package lists... Done
  1. Check for duplicate ports Check the ports that are used more than once. Check the code because the target port is specified when Flask starts.

main.py


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True)

Check the process using port 5000 with the lsof command (Note that if you do not limit the target with the -i option, a large amount will be extracted.)

(base) root@e8cf64ce12e9:/home/continuumio# lsof -i :5000
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python  881 root    4u  IPv4 237229      0t0  TCP *:5000 (LISTEN)
python  901 root    4u  IPv4 237229      0t0  TCP *:5000 (LISTEN)
python  901 root    5u  IPv4 237229      0t0  TCP *:5000 (LISTEN)
  1. Terminate unnecessary processes from the extracted list.

--kill end command. Noisy name. ---9 Forced termination -: Xxxx port number

Check the details with the "man command"

(base) root@e8cf64ce12e9:/home/continuumio# kill -9 901

that's all

Recommended Posts

Error in Flask OSError: [Errno 98] Address already in use
Date of Address already in use error in Flask
Resolve the Address already in use error
ยท Address already in use solution
Use <input type = "date"> in Flask
If you get Error: That port is already in use. In Django
Minimum knowledge to use Form in Flask
Tips when amateurs use Flask in Visual Studio
Use a custom error page in python / tornado
Error in random.shuffle
Error in Pyinstaller
Error in TensorBoard