Python QT/PySide processEvents调用锁定
为什么对processEvents的调用会阻止在长达9秒的时间内不执行任何操作 我有一个基于PySide的QT接口的应用程序,其中UI代码作为低层实际应用程序逻辑上的解耦层。当用户执行一个操作,该操作执行可能会运行一段时间的低级应用程序逻辑时,实际发生的情况是:Python QT/PySide processEvents调用锁定,python,qt,pyside,Python,Qt,Pyside,为什么对processEvents的调用会阻止在长达9秒的时间内不执行任何操作 我有一个基于PySide的QT接口的应用程序,其中UI代码作为低层实际应用程序逻辑上的解耦层。当用户执行一个操作,该操作执行可能会运行一段时间的低级应用程序逻辑时,实际发生的情况是: 直接在GUI线程上显示进度对话框 直接在GUI线程上,低级逻辑启动工作线程 直接在GUI线程上,低级逻辑循环更新进度对话框(间接/解耦),并通过QtGui.qApp.processEvents()勾选应用程序事件队列(再次间接/解耦)
while not completed_event.wait(0.1) and not work_state.is_cancelled():
work_completeness, work_description = work_state.get_completeness(), work_state.get_description()
for client in self.clients:
if work_completeness != last_completeness or work_description != last_description:
client.event_prolonged_action_update(client is acting_client, work_description, step_count * work_completeness)
# THE LAST CALL TO THE NEXT LINE LOCKS UP FOR NO REASON
client.event_tick(client is acting_client)
last_completeness, last_description = work_completeness, work_description
PySide/QT层客户端事件_tick函数:
def event_tick(self, active_client):
# THIS IS WHERE THE LOCK UP HAPPENS
QtGui.qApp.processEvents()
PySide/QT层中的信号/插槽使用情况,以获取GUI线程上发生的工作线程调用:
def event_pre_line_change(self, active_client, line0, line_count):
self.pre_line_change_signal.emit((line0, line_count))
def event_post_line_change(self, active_client, line0, line_count):
self.post_line_change_signal.emit((line0, line_count))
def event_uncertain_reference_modification(self, active_client, data_type_from, data_type_to, address, length):
self.uncertain_reference_modification_signal.emit((data_type_from, data_type_to, address, length))
我之所以使用signals/slot将工作线程上的调用委托给GUI线程,是因为这是PySide/QT所需要的,因为它们将更新UI
如果您想深入挖掘,请参见复制案例:
- 根据GitHub项目自述文本下载并运行
- 下载“NEURO”(