wxpython ProgressDialog 分段错误(lin,不是 win)
wxpython ProgressDialog segmentation fault (lin, not win)
直到最近,我在 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 服务器上运行不正常。据推测,突然的变化与最近的图书馆更新有关。确切的错误信息是:
Segmentation fault (core dumped)
当 运行 带有 pdb 的代码时也会发生同样的情况。
我不确定如何继续识别和解决问题,欢迎提出任何建议。提前致谢。
对 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()
UPDATE - 我刚刚用 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)
直到最近,我在 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 服务器上运行不正常。据推测,突然的变化与最近的图书馆更新有关。确切的错误信息是:
Segmentation fault (core dumped)
当 运行 带有 pdb 的代码时也会发生同样的情况。
我不确定如何继续识别和解决问题,欢迎提出任何建议。提前致谢。
对 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()
UPDATE - 我刚刚用 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)