python环境配置安装socket_需要关闭python socket /在我的开发环境中找到当前正在运行的服务器...

在学习Python Flask框架时,遇到了服务器关闭后仍然占用端口的问题。尝试运行'python app.py'启动服务器,然后关闭,但服务器似乎并未真正关闭,导致再次运行时出现'Address already in use'错误。怀疑可能是SQLite数据库没有正确关闭。目前解决方案是在Linux环境下使用'lsof -i:5000'命令找出占用该端口的进程并关闭。
摘要由CSDN通过智能技术生成

I'm trying to learn python (using the Flask micro-framework) and I am confused because somewhere in my code i'm keeping the server open I believe.

I spin up my server with 'python app.py' and then close it however.... it still lives!

I'm not sure how this is possible but i must have done something wrong with a connection.

There are two questions here really.

First: How can I find the active connection/socket and close it

Second: Is there a way I can diagnose what is having an open connection, my hunch is that sqlLite is not closing as it is the last thing I implemented.

This is a one file application (minus a config file and static content) so I can post the code if required.

Error generated (Folder locations changed):

/Development/flask_projects/test_email/env/bin/python /Development/flask_projects/test_email/app.py

* Running on http://127.0.0.1:5000/

Traceback (most recent call last):

File "Development/flask_projects/test_email/app.py", line 58, in

app.run()

File "Development/flask_projects/wtchn_email/env/lib/python2.7/site-packages/Flask-0.8-py2.7.egg/flask/app.py", line 703, in run

run_simple(host, port, self, **options)

File "/Library/Python/2.7/site-packages/Werkzeug-0.7.1-py2.7.egg/werkzeug/serving.py", line 612, in run_simple

test_socket.bind((hostname, port))

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth

return getattr(self._sock,name)(*args)

socket.error: [Errno 48] Address already in use

解决方案

If you use linux you can use lsof to find out which process is using a given port, you might have to install it first though, usage is pretty simple:

lsof -i :5000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值