简体   繁体   English

python管道(stdin)太快

[英]python pipe (stdin) too fast

I have a following question: Consider flowing data through pipe to python script and processing it there line by line. 我有以下问题:考虑通过管道将数据流到python脚本并在那里逐行处理。 The rate of lines of text going to the pipe is very fast (sys.stdin.readline ), and what if lines of text are coming too fast for script to handle, what happens then? 进入管道的文本行的速度非常快(sys.stdin.readline),如果文本行的速度太快而脚本无法处理,那又会怎样呢? Will stdin read lines in order or the newest one? stdin会按顺序读取行还是最新的行?

The pipe is managed by the operating system: One process writes to the pipe, the OS buffers what was written and passes it on to the reading process. 管道由操作系统管理:一个进程将其写入管道,操作系统会缓冲已写入的内容,并将其传递给读取过程。 If the buffer of the pipe is full, subsequent write operations of the writing process will simply block until there is enough space in the buffer again. 如果管道的缓冲区已满,则写入过程的后续写入操作将简单地阻塞,直到缓冲区中再次有足够的空间为止。

So in short, the OS makes sure nothing gets lost, and you don't have to worry about it. 简而言之,该操作系统可确保一切都不会丢失,您不必担心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM