解决python web项目意外关闭,但占用端口的问题

问题描述

因为项目强制关闭,但是服务还在运行,导致重新运行项目时候 提示地址已经使用(端口被占用)

/usr/bin/python3.5 python-login-demo/index.py
http://0.0.0.0:8080/
Traceback (most recent call last):
 File "/var/www/git/mine/python-login-demo/index.py", line 64, in <module>
 application.run()
 File "/usr/local/lib/python3.5/dist-packages/web/application.py", line 341, in run
 return wsgi.runwsgi(self.wsgifunc(*middleware))
 File "/usr/local/lib/python3.5/dist-packages/web/wsgi.py", line 59, in runwsgi
 return httpserver.runsimple(func, server_addr)
 File "/usr/local/lib/python3.5/dist-packages/web/httpserver.py", line 177, in runsimple
 server.start()
 File "/usr/local/lib/python3.5/dist-packages/web/wsgiserver/wsgiserver3.py", line 1669, in start
 raise socket.error(msg)
OSError: No socket could be created -- (('0.0.0.0', 8080): [Errno 98] Address already in use)

解决方法

查找(<strong>lsof</strong>)该进程, 并结束(<strong>kill</strong>)该进程 即可.

$ lsof -i:8080               130 ↵
COMMAND  PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python3.5 31982 willike 3u IPv4 593966  0t0 TCP *:http-alt (LISTEN)

$ sudo kill 31982

以上这篇解决python web项目意外关闭,但占用端口的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持呐喊教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。