python socket.error:[Errno 98]地址已在使用中[关闭]


76

当我设置application.py时,它显示socket.error:[Errno 98]地址已在使用中。

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

您需要提供有关该应用程序的更多信息。
电台

1
如果您知道该地址要使用的地址,则可以使用查找该地址的其他内容netstat
路加福音

更改address并向我们​​提供更多代码。
维克多·卡斯蒂略·托雷斯


31
sudo lsof -t -i tcp:8000 | xargs kill -9
wadadaaa

Answers:


133

显然,有另一个进程正在监听端口。您可以使用以下命令找出该过程:

$ lsof -i :8000

或更改龙卷风应用程序的端口。龙卷风的错误信息不明确对此。


1
在我由Python应用程序创建套接字且应用程序被强制退出的情况下,此答案不起作用。请按照链接,看到了答案由阿尤布laaziz
emmmphd

35
与我一起使用sudo端口5000(对于Flask应用程序),例如sudo lsof -i :5000检测侦听端口的进程,然后sudo kill -9 <process_id>
Inverbis

4
执行此命令后,什么都没有显示(即使sudo lsof -i :8000),但仍然出现相同的错误。:(
ytu '18

1
我正在使用sudo没有显示任何操作。
ScipioAfricanus

2
对于那些面临这个问题有没有从即将到来netstat或者lsof,如果你正在测试/重新启动脚本,它调用socket.bind(),你可能会发现地址可能仍然在使用了一段时间,甚至杀死复杂的过程后:结帐这个答案
EricLavault
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.