wxPython window 在 RPi 上随机冻结并且之后行为怪异

wxPython window randomly freezes on RPi and acts weird afterwards

此问题仅出现在 RPi(3B+,Raspbian Buster)上。我运行我Mac上的程序没有任何问题。

我的程序的简短描述:

进入主循环后,当指定的按钮被按下时,程序进入第二个线程和另一个循环(称之为请求循环)。再次按下按钮可以离开请求循环。这个请求循环每 10 秒通过 url 请求一个 xml table,然后用 ElementTree 解析,排序并显示在 wx.grid.Grid 中。我使用 grid.ForceRefresh 来确保网格已更新。

我希望以下片段有助于理解以上内容:

    def on_btnrun(self, event):
        global run
        if self.btnrun.Label == "Start":
            run = True
            thrupt = threading.Thread(target=self.thrupdate)
            thrupt.start()
            self.btnrun.SetLabel("Ende")

        elif self.btnrun.Label == "Ende":
            run = False
            self.btnrun.SetLabel("Start")


     def thrupdate(self):
         while run is True:
            reset()
            self.grid.ClearGrid()
            update(self.grid)
            self.grid.ForceRefresh()
            time.sleep(10)

问题:

现在如标题中所述,整个 wx Window 在通过大约 5 到 20 次请求循环后冻结。这完全是随机发生的,我找不到任何规律。尽管程序保持 运行ning,因为它仍然在每个周期打印终端中的输出(我添加此功能用于测试)。 当我现在打开另一个位于 wx Window 上的 window (例如菜单下拉菜单)时,它将被复制到 wx Window 并在我关闭它后保留在那里。

这里有一些图片可以更好地理解我的意思(忽略我没有提到的所有其他小部件,它们只是非功能性占位符)。

Image of the wx Window before it freezes

Image of the wx Window after it freezes

Image of the wx Window after opening and closing the dropdown menu

Extra-Info:在 RPi 上构建 wxPython 时,我收到了一些警告,每次我 运行 该程序时,我都会收到以下警告(它说实际时间而不是时间):

(program.py:1666): Gtk-Critical **: time: gtk_distribute_natural_allocation: assertion ‚extra_space >= 0‘ failed

问题:

我不知道为什么会发生这种情况。 Raspbian 上的 wxPython 不是 stable 吗?还是构建部分失败了?还是树莓派渲染能力不够?

在update()方法的细节中使用wx.CallAfter解决了。