python bad file descriptor_python socket.error: [Errno 9] Bad file descriptor
今天编写一个tcp服务器的时候出现错误:socket.error: [Errno 9] Bad file descriptor
出现的原因是连接已经被关闭,部分语句还在试图调用已经关闭的连接。
代码片段:
while True:
data = tcpCliSock.recv(BUFSIZE)
if not data:
break
tcpCliSock.send("hello")
tcpCliSock.close()
代码分析:
tcpCliSock.close()关闭连接后,while还没有结束,又调用了data = tcpCliSock.recv(BUFSIZE),引发了错误。
代码修改:
把tcpCliSock.close()放到while循环外就可以了。
修改后的代码:
while True:
data = tcpCliSock.recv(BUFSIZE)
if not data:
break
tcpCliSock.send("hello")
tcpCliSock.close()
python bad file descriptor_python socket.error: [Errno 9] Bad file descriptor相关推荐
- python socket.error: [Errno 24] Too many open files
以openwrt AR9331开发板为例,socket连接到1019个就报错 "python socket.error: [Errno 24] Too many open files&quo ...
- python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接。问题解决方案
python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接.问题解决方案: 前几天使用python读取网页.因为对一个网站大量的使用urlopen操作,所以 ...
- python socket.error: [Errno 10054] 解决方法
python socket.error: [Errno 10054] 解决方法 参考文章: (1)python socket.error: [Errno 10054] 解决方法 (2)https:// ...
- python [Errno socket error] [Errno 104] Connection reset by peer
python [Errno socket error] [Errno 104] Connection reset by peer 原因可能是多方面的,不过更常见的原因是: ①:服务器的并发连接数超过了 ...
- HBase: Thrift写数据报错——socket.error: [Errno 32] Broken pip
博主用的是python来读写hbase 需要安装 pip install thrift 和 pip install hbase-thrift hbase客户端创建: from thrift impor ...
- linux socket errno 4,解决socket.error: [Errno 98] Address already in use问题
刚刚开始使用flask框架写了两个小程序.然后我先访问了第一个"Hello,Web"的小程序,运行通过,然后想看看第二个inputname的程序是不是写对,但是linux报错: s ...
- python socket.error: [Errno 48] Address already in use
转载自: http://blog.csdn.net/args_/article/details/52609987 解决方案: 打开终端,输入sudo lsof -i:XXXX xxxx是你刚刚用来开启 ...
- scrapy-cluster : socket.error: [Errno 98] Address already in use解决方法
You could check which process is using that port using sudo netstat -nlp | grep :5343 and then kill ...
- python描述器descriptor_python装饰器decorator、描述器descriptor
背景 image.png 装饰器decorator 返回值为另一函数的函数,通常使用 @wrapper语法. 装饰器的常见例子包括 装饰器语法只是一种语法快捷方式,以下两个函数定义在语义上完全等价: ...
最新文章
- jQuery弹出窗口浏览图片
- java nei_NEI 接口管理平台
- synchronized(xxx.class)
- 科普!程序员分不清万圣节和圣诞节?
- 微型计算机原理第二版学习辅导,微型计算机原理及应用学习辅导.pdf
- Oracle 密码过期问题
- 软件测试工程师—从零到月入过万你只需要看这篇就够了(基础篇)
- CVPR2021论文整理
- 京东风格的移动端Vue组件库NutUI2.0来啦
- securecrt安装mysql_centos安装mysql(for 小白)
- dubbo3.0源码编译问题
- ManualResetEvent使用说明
- 在网上看到SpiceWorks是一个免费但很强大的HELPDESK系统
- 信息安全必备的8张思维导图
- 自定义滚动条、tbody加滚动条
- java连接云服务Hadoop伪分布式错误:Call From LAPTOP-14BPR3NI/192.168.1.2 to node1:9000 failed on connection
- NET新手遭遇问题(九)
- 浅谈我国中小企业融资的问题及对策_毕业论文(20180404104959)
- SGU 482 Impudent Thief dp
- 蓝屏代码: DRIVER_UNLOADED_WITHOUT_CANCELLING_PENDING_OPERATIONS bootsafe64.sys