首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Python和sendfile[通俗易懂]

sendfile(2) is a UNIX system call which provides a “zero-copy” way of copying data from one file descriptor (a file) to another (a socket). Because this copying is done entirely within the kernel, sendfile(2) is more efficient than the combination of “file.read()” and “socket.send()”, which requires transferring data to and from user space. This copying of the data twice imposes some performance and resource penalties which sendfile(2) syscall avoids; it also results in a single system call (and thus only one context switch), rather than the series of read(2) / write(2) system calls (each system call requiring a context switch) used internally for the data copying. A more exhaustive explanation of how sendfile(2) works is available here, but long story short is that sending a file with sendfile() is usually twice as fast than using plain socket.send(). Typical applications which can benefit from using sendfile() are FTP and HTTP servers.

01

Python 2.7.x 和 3.x 版

python现在很火,最近花了些时间去了解了一下,最初了解的是2.7.x版本,感觉,从书写上是很不习惯,少了一双大概号,取而代之的是缩进;然后跟kotlin和swift一样省去了每行的分号,象我们这种分号强迫症的人真心的不习惯;还有!True的条件改成not True、while后面可以跟else等等这些,真心不习惯啊!用2.7.x做了几天的测试,基本慢慢算有个了解了,也试着爬了些行业网的数据,感觉这个比PHP写爬虫方便很多。然后昨晚就在家里装了个3.X的版本,很悲催的发现,原来写的有很多的错误,万般无奈的检查之下,发现语句上是没什么问题,只是3.X版本不兼容部分的语句,例如最常用的print,raw_input都不一样了,今天花了些时间查一查,并总结了一下它们的区别。

03
领券