【问题标题】:wxpython ProgressDialog segmentation fault (lin, not win)wxpython ProgressDialog 分段错误(lin,不是win)
【发布时间】:2015-10-30 23:57:45
【问题描述】:

直到最近,我一直在 Windows (8) 和 Linux (XUbuntu 14.04) 环境中处理和运行的代码在创建 wx ProgressDialog 时开始出现分段错误,但仅在后一个平台上。这个最小的代码示例说明了这个问题:

#!/usr/bin/python

import wx
import time

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'test ',
         pos=(200, 100), size=(120, 160))

        self.Show(True)
        but = wx.Button(self, -1,label="Click me!", pos=(10,10), size=(100,100))
        but.Bind(wx.EVT_BUTTON, self.click)

    def click(self,evt):
        progress_dlg = wx.ProgressDialog('Progress', 'Testing...', -1,
                                             style=wx.PD_ELAPSED_TIME)

        for i in range(10):
           time.sleep(0.5)
           progress_dlg.Pulse()

        progress_dlg.Destroy()


if __name__ == "__main__":
    application = wx.App(False)
    window = MyFrame()
    application.MainLoop()

这段代码在我的 Windows 机器上运行良好,但在我们的 Linux 服务器上却不行。据推测,突然的变化与最近的一些图书馆更新有关。确切的错误信息是:

分段错误(核心转储)

使用 pdb 运行代码时也会发生同样的情况。

我不确定如何继续识别和解决问题,并欢迎任何建议。提前致谢。

【问题讨论】:

标签: python linux windows wxpython


【解决方案1】:

对 Pulse() 的调用似乎也导致它在我的系统上中断。我在 Xubuntu 14.04 上使用 wxPython 2.8.12.1 和 Python 2.7。如果我将Pulse 换成Update,它可以正常工作:

import wx
import time

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'test ',
         pos=(200, 100), size=(120, 160))

        self.Show(True)
        but = wx.Button(self, -1,label="Click me!", pos=(10,10), size=(100,100))
        but.Bind(wx.EVT_BUTTON, self.click)

    def click(self,evt):
        progress_dlg = wx.ProgressDialog('Progress', 'Testing...', -1,
                                             style=wx.PD_ELAPSED_TIME)

        for i in range(10):
            time.sleep(0.5)
            progress_dlg.Update(i)

        progress_dlg.Destroy()


if __name__ == "__main__":
    application = wx.App(False)
    window = MyFrame()
    application.MainLoop()

更新 - 我刚刚用 wxPython 3.0.0.0 尝试了你的代码,它给了我以下回溯:

Traceback (most recent call last):
  File "test.py", line 15, in click
    style=wx.PD_ELAPSED_TIME)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_windows.py", line 3764, in __init__
  _windows_.ProgressDialog_swiginit(self,_windows_.new_ProgressDialog(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion "pos <= m_rangeMax" failed at  ../src/gtk/gauge.cpp(95) in SetValue(): invalid value in wxGauge::SetValue()

这让我想到在实例化 ProgressDialog 时需要设置最大值。我试过了,它有效。只需将该行更改为以下内容:

progress_dlg = wx.ProgressDialog('Progress', 'Testing...', maximum=10,
                                         style=wx.PD_ELAPSED_TIME)

【讨论】:

  • 是的,该参数不是像通常的 wx API 那样的 ID 值,并且使用的 GTK 小部件不能安全地处理值设置的负数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-14
  • 2021-03-02
相关资源
最近更新 更多