php sigpipe,Python的SIGPIPE信号「建议收藏」

php sigpipe,Python的SIGPIPE信号「建议收藏」Haveyoueverseenasocket.error:[Errno32]BrokenpipemessagewhenrunningaPythonWebserverandwonderedwhatthatmeans?Theruleisthatwhenaprocesstriestowritetoasocketthathasalre…

大家好,又见面了,我是你们的朋友全栈君。

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.net/139298.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 手机游戏开发现状分析[通俗易懂]

    手机游戏开发现状分析[通俗易懂]随着近年来手机的日渐普及,手机游戏已经成为整个游戏领域发展速度最快的部分。根据英国某媒体研究公布的统计数据,今年的手机游戏市场的产值已经达到5.87亿美元,比去年年翻了一番。该公司预计到今后几年里这一市场的产值将达到目前的6倍,增至38亿美元。 我国的手机游戏在最近一年,也有了长足的发展。但是就其规模而言,还远远没有达到国外的水平。这其中原因很多,但有一点是可以肯定的,我国的手机游戏前景是光明

    2022年4月30日
    42
  • 3种常用的图片压缩方法

    3种常用的图片压缩方法3种常用的图片压缩方法:把图片上传到阿里云或七牛云,借用云端的图片缩放技术进行压缩。后端对图片尺寸大小进行压缩。前端用Canvas作为媒介压缩图片。作为一名前端攻城狮,主要介绍用Canvas作为媒介压缩图片。…

    2022年6月18日
    33
  • Python 实现异步调用函数

    Python 实现异步调用函数async_call.py#coding:utf-8fromthreadingimportThreaddefasync_call(fn):defwrapper(*args,**kwargs):Thread(target=fn,args=args,kwargs=kwargs).start()returnwrappertest.p…

    2022年7月11日
    22
  • 解决Win键不能用的问题[通俗易懂]

    解决Win键不能用的问题[通俗易懂]问题描述:突然有一次,乱按了一通键盘,突然win键就不能使用了;win键既可以启动开始界面,同时又是win自带的快捷键的关键按键,比较重要。解决方法:发现自己的问题就是:按fn+F12(他会带一个小锁的键)就是锁定Win键;我解决的办法就是:按fn+Prtsc(他会带一个小钥匙的键)这样就可以使用Win键了;可能是以为电脑而异吧,多试一下上面的按键…

    2022年6月3日
    36
  • aero是什么意思啊_自动驾驶视觉算法

    aero是什么意思啊_自动驾驶视觉算法数据集介绍aeroscapes数据集下载链接AeroScapes航空语义分割基准包括使用商用无人机在5到50米的高度范围内捕获的图像。该数据集提供3269张720p图像和11个类别的真实掩码。数据加载dataloder写法(基于pytorch)由于该数据集提供了掩码图,因此不需要进行掩码图转换。下载完成后,文件结构如下:ImageSets文件夹:存放了两个txt文件,划分了训练集和验证集。JPEGImages文件夹:存放了RGB图像。SegmentationClass

    2022年8月15日
    5
  • WindowManager.LayoutParams.FLAG_SECURE_congestion window

    WindowManager.LayoutParams.FLAG_SECURE_congestion windowpublicstaticclassWindowManager.LayoutParamsextends ViewGroup.LayoutParamsimplements Parcelablejava.lang.Object   ?android.view.ViewGroup.LayoutParams    ?

    2022年9月21日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号