已以非阻塞方式打开的管道上的 Python readline
我有一个以非阻塞模式打开的 Linux fifo。正如预期的那样,当我对文件对象调用 read 时,它会立即返回。我使用 select 来确保没有忙等待,但当有任何可用数据时我的程序仍然会收到通知。出于好奇,我尝试了 readline 函数,并惊讶地发现 readline 会阻塞,直到找到换行符。我通过 top 检查了处理器的使用情况,看起来 readline 并不忙等待。由于我的应用程序对性能敏感,因此我想知道在非阻塞套接字上使用 readline 时是否会对性能产生任何影响。
I have a Linux fifo that has been opened in non-blocking mode. As expected, when I call read on the file object, it returns immediately. I use select to make sure there is no busy waiting, but that my program is still notified when there is any data available. Out of curiosity, I tried the readline function and was surprised to find that readline blocks until a newline character is found. I examined the processor usage via top and it seems like readline does not busy wait. Since my application is performance sensitive, I am wondering if there are any performance implications when using readline on a non-blocking socket.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python readline 的核心部分在 fileobject.c:get_line 中,这里
没有
什么特别的事情发生。你确定你的观察结果就是你所认为的那样吗?
The core part of Python's readline is in fileobject.c:get_line and is
where
There's nothing special going on. Are you sure your observations are what you think they are?