简体   繁体   English

从管道读取Python

[英]Reading from pipe Python

I have a process that gathers information from the web and stores into files. 我有一个从网络收集信息并将其存储到文件中的过程。 I have another process that has the purpose to use this data to do analysis. 我还有另一个过程,其目的是使用此数据进行分析。 That is, P1 writes the data to files and P2 used these information to do analysis. 也就是说,P1将数据写入文件,P2使用这些信息进行分析。

Now my problem is with P2. 现在我的问题是P2。 How can I make P2 get input from the data files as a stream? 如何使P2作为流从数据文件中获取输入? Eg when the bytes are received from P1 to be also input to P2. 例如,当从P1接收到字节并将其也输入到P2时。

I am thinking of using IPC or something similar to that. 我正在考虑使用IPC或类似的东西。 I thinked of using PIPES but the problem is that the P1 may block until P2 reads the data. 我考虑过使用PIPES,但问题是P1可能会阻塞,直到P2读取数据为止。 The P1 should never stop receiving data. P1永远不要停止接收数据。 The P2 can be extremely late. P2可能会非常晚。 One idea is to use a different thread to send the data to the pipe until there is a time out. 一种想法是使用另一个线程将数据发送到管道,直到超时为止。

Is this approach correct? 这种方法正确吗?

Seems that indeed named pipes are your tool for this. 似乎确实命名的管道是您的工具。

Very easy to consume as regular files from python or using python's os module 很容易从python或使用python的os模块作为常规文件使用

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

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