100

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
8
  • You need to provide more information about the application.
    – Radio-
    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.
    – Luke
    Jul 22, 2013 at 5:11
  • Change the address and provide us more code please. Jul 22, 2013 at 5:13
  • @emuu: stackoverflow.com/questions/4465959/…
    – thinker3
    Sep 4, 2013 at 13:40
  • 40
    sudo lsof -t -i tcp:8000 | xargs kill -9
    – wadadaaa
    Nov 1, 2017 at 8:31

1 Answer 1

164

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.

10
  • 2
    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 Mar 27, 2017 at 8:52
  • 46
    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>
    – Inverbis
    Aug 8, 2017 at 15:30
  • 5
    Nothing shows up after I execute this command (even sudo lsof -i :8000), but still I am getting the same error. :(
    – ytu
    Jul 3, 2018 at 3:50
  • 1
    I am using sudo didnt show anything op. Jul 15, 2019 at 19:13
  • 9
    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. Oct 25, 2019 at 20:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.