首页 > 解决方案 > 使用 PyQt5 和 GNURadio 避免退出代码 -1073741819 (0xC0000005)

问题描述

我在 Windows 10 上,我必须编写一个 Python 脚本,该脚本调用一个带有 PYQT5 GUI 图的 GNURadio 应用程序。从使用 GNURadio Companion 制作的顶级块类开始,我需要添加一些功能:

  1. 应该安排 GNURadio 应用程序的启动(我正在使用 aps 后台调度程序,因为我需要释放主线程,在该主线程中我需要在套接字上做一些事情)
  2. 该应用程序应在一定秒数后自动终止(我尝试使用 threading.Timer 模块)。

这是一个由 GNURadio 自动生成的 main 函数的示例。

def main(top_block_cls=test01, options=None):

   if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
       style = gr.prefs().get_string('qtgui', 'style', 'raster')
       Qt.QApplication.setGraphicsSystem(style)
   qapp = Qt.QApplication(sys.argv)

   tb = top_block_cls()
   tb.start()
   tb.show()

   def sig_handler(sig=None, frame=None):
       tb.stop()
       tb.wait()
       Qt.QApplication.quit()

   signal.signal(signal.SIGINT, sig_handler)
   signal.signal(signal.SIGTERM, sig_handler)

   timer = Qt.QTimer()
   timer.start(500)
   timer.timeout.connect(lambda: None)

   qapp.exec_()

由于aps后台调度程序在与主线程不同的线程(即ThreadPoolExecutor-0_0)上启动脚本,因此信号模块引发错误,因此我认为它不能用于我的目的。我尝试使用下一个代码,其中我删除了信号线并添加了调用相同 sig_handler 的计时器。该应用程序关闭,但我得到一个退出代码 -1073741819 (0xC0000005),它关闭了整个程序,甚至是主线程,而我必须保持它运行。

def main(seconds: float, top_block_cls=test01, options=None):

   if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
       style = gr.prefs().get_string('qtgui', 'style', 'raster')
       Qt.QApplication.setGraphicsSystem(style)
   qapp = Qt.QApplication(sys.argv)

   tb = top_block_cls()
   tb.start()
   tb.show()

   def sig_handler(sig=None, frame=None):
       tb.stop()
       tb.wait()
       Qt.QApplication.quit()
   
   Timer(seconds, sig_handler).start()

   timer = Qt.QTimer()
   timer.start(500)
   timer.timeout.connect(lambda: None)

   qapp.exec_()

有谁知道如何解决它?

标签: pythonpyqt5gnuradioapschedulergnuradio-companion

解决方案


推荐阅读