python

关注公众号 jb51net

关闭
首页 > 脚本专栏 > python > python web项目关闭占用端口

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

作者:ITAKEN''''S PAGES

今天小编就为大家分享一篇解决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项目意外关闭,但占用端口的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文