简体   繁体   English

使用QTimer在Python中流式传输大型数据文件

[英]Using QTimer for Streaming Large Data File in Python

I'll start with saying that I have working code...but that doesn't make it ideal code which is why I want to run my approach by the community. 我首先要说的是我有有效的代码...但这并不能使它成为理想的代码,这就是为什么我要由社区来使用我的方法。 I'm trying to do this the "QT way" which is forcing me down roads I don't normally go. 我正在尝试以“ QT方式”执行此操作,这迫使我沿着通常不去的路走。

I have some large 400+mb binary files containing raw time variant data. 我有一些包含原始时变数据的400 + mb二进制文件。 I need to plot this data to the user so that the data playback matches the time duration of the recording. 我需要将此数据绘制给用户,以便数据回放与记录的持续时间匹配。 I have a working approach using a QTimer.timeout to trigger a file read. 我有一个使用QTimer.timeout触发文件读取的有效方法。 I read x amount of bytes, and when the read is complete I emit a signal to trigger the plotting operation. 我读取了x个字节,读取完成后,我发出一个信号来触发绘图操作。 By adjusting my timeout duration I can control the rate of plotting without blocking my interface(not blocking the GUI is key). 通过调整超时时间,我可以控制绘图速度而不会阻塞我的界面(不阻塞GUI是关键)。 This seems to work, but it feels overly complicated for something as simple as a file.read. 这似乎可行,但是对于像file.read这样简单的事情,感觉却过于复杂。

When I receive data in a stream over TCP I can use the socket.readReady signal to tell me when to process data. 当我通过TCP在流中接收数据时,可以使用socket.readReady信号告诉我何时处理数据。 Since the data is arriving serially in time, it naturally looks right over the TCP stream. 由于数据是按时间顺序到达的,因此自然看起来就在TCP流上。

I have essentially duplicated the readReady of a socket by using fread and emitting a signal. 我基本上通过使用fread并发出信号来复制套接字的readReady。 Does this sound like a reasonable approach? 这听起来像是一种合理的方法吗?

An alternative might be a plotting buffer being somewhat bigger than what you need to display. 另一种可能是绘图缓冲区比您需要显示的缓冲区要大一些。 If it runs short of values you fill it up. 如果它缺少值,则将其填满。 If you do this in a thread you can ensure data availability without the need of timers or read ready signals. 如果您在线程中执行此操作,则可以确保数据可用性而无需计时器或读取就绪信号。 You would just have to keep track of which data has already been read and the direction in time. 您只需要跟踪已读取的数据以及及时的方向即可。

An alternative could be using the QFile::map() function to map the right slice of data to display into memory for direct access without any file reading. 另一种选择是使用QFile :: map()函数将正确的数据切片映射到内存中以直接访问而无需读取任何文件。 I guess that should be fast enough for fast displaying depending on the slice size. 我想这应该足够快以便根据切片大小快速显示。 This approach may be combined with the buffer approach above to avoid excessive mapping. 可以将这种方法与上面的缓冲区方法结合起来,以避免过多的映射。 This would mean to map a slice larger that currently needed. 这将意味着映射比当前需要更大的切片。

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

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