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

yipeiwu_com6年前Python基础

问题描述

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

/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项目意外关闭,但占用端口的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python的IDEL增加清屏功能实例

为idle增加一个清屏的扩展ClearWindow就可以了(在http://bugs.python.org/issue6143中可以看到这个扩展的说明)。 下面我说安装使用的方法。首先下...

python显示天气预报

复制代码 代码如下:import urllib2import jsonimport stringurl ='http://m.weather.com.cn/data/101090502....

python 变量初始化空列表的例子

python 不能写new_loss=old_loss=[] 这样 两个变量实际上是同一个list 要分开写new_loss=[] Old_loss=[] 以下列数据文件为例: de...

Python统计列表中的重复项出现的次数的方法

本文实例展示了Python统计列表中的重复项出现的次数的方法,是一个很实用的功能,适合Python初学者学习借鉴。具体方法如下: 对一个列表,比如[1,2,2,2,2,3,3,3,4,4...

python+pandas+时间、日期以及时间序列处理方法

先简单的了解下日期和时间数据类型及工具 python标准库包含于日期(date)和时间(time)数据的数据类型,datetime、time以及calendar模块会被经常用到。 dat...