简体   繁体   English

PyQt4线程化:将数据发送回线程

[英]PyQt4 Threading: Sending data back to a thread

I'm writing a program, with a PyQt frontend. 我正在编写一个带有PyQt前端的程序。 To ensure that the UI doesn't freeze up, I use QThreads to emit signals back to the parent. 为了确保UI不会冻结,我使用QThreads将信号发送回父级。 Now, I have reached a point where I need my thread to stop running, emit a signal back to the parent, then wait on the parent to return an approval for the thread to continue (after the user interacts with the UI a little bit). 现在,我到达了需要线程停止运行,向父级发出信号,然后等待父级返回批准以继续执行线程的位置(在用户与UI进行一点交互之后)。 。

I've been looking into the QMutex class, along with QThread's wait function. 我一直在研究QMutex类以及QThread的wait函数。

How should I go about doing this properly? 我应该如何正确地做到这一点?

One approach is using a condition variable . 一种方法是使用条件变量

In my code, however, I prefer using Python's built-in Queue objects to synchronize data between threads. 但是,在我的代码中,我更喜欢使用Python的内置Queue对象在线程之间同步数据。 While I'm at it, I use Python's threads as opposed to PyQt threads, mainly because it allows me to reuse the non-GUI part of the code without an actual GUI. 当我使用它时,我使用Python的线程而不是PyQt线程,主要是因为它允许我在没有实际GUI的情况下重用代码的非GUI部分。

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

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