php sigpipe,Python的SIGPIPE信号「建议收藏」
大家好,又见面了,我是你们的朋友全栈君。
Have you ever seen a socket.error: [Errno 32] Broken pipe message when running a Python Web server and wondered what that means?
The rule is that when a process tries to write to a socket that has already received an RST packet, the SIGPIPE signal is sent to that process which causes the Broken pipe socket.error exception.
Here are two scenarios that you can try that cause SIGPIPE signal to be fired.
1. Server may send an RST packet to a client to abort the socket connection but the client ignores the packet and continues to write to the socket.
To test that behavior. install Cynic, run it
CODE:01.$ cynic
02.INFO [2012-06-08 05:06:37,040] server: Starting ‘HTTPHtmlResponse’ on port 2000
03.INFO [2012-06-08 05:06:37,040] server: Starting ‘HTTPJsonResponse’ on port 2001
04.INFO [2012-06-08 05:06:37,040] server: Starting ‘HTTPNoBodyResponse’ on port 2002
05.INFO [2012-06-08 05:06:37,040] server: Starting ‘HTTPSlowResponse’ on port 2003
06.INFO [2012-06-08 05:06:37,040] server: Starting ‘RSTResponse’ on port 2020
07.INFO [2012-06-08 05:06:37,040] server: Starting ‘RandomDataResponse’ on port 2021
08.INFO [2012-06-08 05:06:37,040] server: Starting ‘NoResponse’ on port 2022
09.INFO [2012-06-08 05:06:37,041] server: Starting ‘LogRecordHandler’ on port /tmp/_cynic.sockand then run the client1.py:
CODE:01.import socket
02.
03.# connect to Cynic’s RSTResponse service on port 2020
04.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
05.s.connect((”, 2020))
06.
07.# first read gets an RST packet
08.try:
09.s.recv(1024)
10.except socket.error as e:
11.print e
12.print
13.
14.# write after getting the RST causes SIGPIPE signal
15.# to be sent to this process which causes a socket.error
16.# exception
17.s.send(‘hello’)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/301743/viewspace-733074/,如需转载,请注明出处,否则将追究法律责任。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139298.html原文链接:https://javaforall.cn
相关文章
- javascript typescript_typescript python
- 不要再写Python for循环了
- 如何查看python源码_python判断路径是否存在
- 超强 Python 数据可视化库,一文全解析
- Python求解两数之和[通俗易懂]
- pythonrandom函数用法_python之random模块函数的使用
- python进制转换函数-Python中进制转换函数的使用
- python采集豆瓣网top250前10和后10电影短评并进行语义分析
- Python继续霸榜,SQL写得溜,面试或许能加分
- Python || 皖事通安康码截图信息简易识别采集
- python之抛出异常(raise语句)「建议收藏」
- python ZipFile: output zip file,ByteIO
- Python+Flask实现的学生培养计划管理系统
- python进制转换函数
- 基于python的安全帽识别安全帽检测可以检测图片,视频流,有界面[通俗易懂]
- python移动app开发_神奇的Kivy,让Python快速开发移动app
- 如何给ESP32-CAM编译micropython
- 【python】分苹果
- 自动化神器!Python 批量读取身份证信息写入 Excel
- (更新时间)2021年3月26日 python基础知识(模块制作)[通俗易懂]