103

when i setup application.py, it shows that socket.error: [Errno 98] Address already in use.

Traceback (most recent call last):
File "application.py", line 121, in <module>
main()
File "application.py", line 117, in main
http_server.listen(options.port)
File "/usr/local/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/tcpserver.py", line 117, in listen
sockets = bind_sockets(port, address=address)
File "/usr/local/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/netutil.py", line 90, in bind_sockets
sock.bind(sockaddr)
File "/usr/local/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
9
  • You need to provide more information about the application. Commented Jul 22, 2013 at 5:10
  • 2
    If you know the address it is trying to use, then you can find out what else is holding that address with netstat. Commented Jul 22, 2013 at 5:11
  • Change the address and provide us more code please. Commented Jul 22, 2013 at 5:13
  • @emuu: stackoverflow.com/questions/4465959/… Commented Sep 4, 2013 at 13:40
  • 42
    sudo lsof -t -i tcp:8000 | xargs kill -9 Commented Nov 1, 2017 at 8:31

1 Answer 1

165

There is obviously another process listening on the port. You might find out that process by using the following command:

$ lsof -i :8000

or change your tornado app's port. tornado's error info not Explicitly on this.

Sign up to request clarification or add additional context in comments.

10 Comments

This answer didn't work under my case where a socket is created by Python application and th application is forced exit. Please follow the link and see the answer by ayoub laaziz
Worked for me with sudo and port 5000 (for a Flask app), e.g. sudo lsof -i :5000 to detect the process listening on the port, and then sudo kill -9 <process_id>
Nothing shows up after I execute this command (even sudo lsof -i :8000), but still I am getting the same error. :(
I am using sudo didnt show anything op.
For those facing this issue with nothing coming up from netstat or lsof, if you are testing/restarting a script that makes a call to socket.bind(), you may find that the address may still be in use for a while even after killing the involved process : checkout this answer.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.