0

Up until recently, a code I have been working on and running in both Windows (8) and Linux (XUbuntu 14.04) environments started to give segmentation faults upon creating a wx ProgressDialog, but only on the latter platform. This minimal code sample illustrates the problem:

#!/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()

This code works fine on my Windows machine, but not on our Linux server. Presumably the sudden change is related to some recent library update. The exact error message is:

Segmentation fault (core dumped)

and the same happens when running the code with pdb.

I am unsure how to proceed to identify and fix the problem and would welcome any suggestions. Thanks in advance.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • Can't say off the bat what the problem is because it's working here. But I'd try putting a `print('ID')` at basically every row to identify the row where your code brings up the segmentation fault, I'm guessing in the `Pulse()` function. And also run `python -m trace --trace myscript.py` – Torxed Aug 07 '15 at 13:58
  • For future references check these as well: http://stackoverflow.com/questions/1623039/python-debugging-tips and http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html – Torxed Aug 07 '15 at 13:59
  • Thanks, I'll dive in to these, there are bound to be some things I have not tried yet. And yes, Pulse() is causing the segmentation fault. – Asellus aquaticus Aug 07 '15 at 14:58

1 Answers1

1

The call to Pulse() does seem to cause it to break on my system as well. I am using wxPython 2.8.12.1 with Python 2.7 on Xubuntu 14.04. If I swap out Pulse for Update, it works fine:

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 - I just tried your code with wxPython 3.0.0.0 and it gives me the following traceback:

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()

This gave me the idea that you need to set the maximum value when you instantiate your ProgressDialog. I tried that and it works. Just change that line to the following:

progress_dlg = wx.ProgressDialog('Progress', 'Testing...', maximum=10,
                                         style=wx.PD_ELAPSED_TIME)
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • Yep, that parameter is not an ID value like the usual wx API, and the GTK widgets used do not safely handle negative numbers for the value setting. – RobinDunn Aug 07 '15 at 19:03