GUI crashing problem help

Hy!
I have a problem concerning my implemented GUI, that is the program
sometimes stops and crashes the GUI and closes the windows. I get an error
like this : python: ../../src/xcb_lock.c:77: _XGetXCBBuffer: Assertion
`((int) ((xcb_req) - (dpy->request)) >= 0)' failed.Aborted

Any help is greatly appreciated!
Here is part of the code:

···

#-----------------------------------------------------------------------#
# Class

class Tuner(wx.Frame):

  def __init__(self, frame):
    wx.Frame.__init__(self, None, -1, "Tunning Stats")
    self.frame = frame
    self.Stop = False

  def StartTune (self):
    
    ##########################################
    # Frame to display Tunning Evolution
    ##########################################
    self.fftwindow = wx.Frame(self.frame,-1, "Tunning",
                    style=wx.FRAME_FLOAT_ON_PARENT|wx.CAPTION|wx.CLOSE_BOX,
                    pos=(200,170), size=(500,500))
    fftwindow = self.fftwindow

    # Create FFT Plot
    self.plot = wx.lib.plot.PlotCanvas(fftwindow, style=wx.RAISED_BORDER)
    size = fftwindow.GetClientSize()
    self.plot.SetInitialSize(size=size)
    self.plot.SetShowScrollbars(False)
    self.plot.SetEnableZoom(True)
    self.plot.SetFontSizeAxis(point=8)
    self.plot.SetFontSizeTitle(point=15)
    
    self.winSizer = wx.BoxSizer(wx.VERTICAL)
    self.winSizer.AddSpacer(20)
    self.winSizer.Add(self.plot)
    self.winSizer.AddSpacer(20)
    self.SetSizer(self.winSizer)
    fftwindow.Fit()
    fftwindow.Show()

    # Just some work...
    while(1):
      if self.Stop:
        time.sleep(2)
        print "stop1"
        fftwindow.Close()
        print "stop2"
        print "stop3"
        return
      for i in range(100): print i
      for i in range(100): print 100-i
#the above prints are just for simulating a process.

  def StopTune(self):
    self.Stop = True

#---------------------------------------------------------------------------------------------#
# GUI

  (....)

  #TUNNING INTERFACE

  # Prepare to Start Tunning
  def OnTune(self,event):
    self.TuneButton.Enable(False)
    self.StopButton.Enable(True)
    self.SetStatusText("Tunning...")
    self.t = Tuner.Tuner(self)
    self.thread = threading.Thread(target=self.__run)
    self.thread.setDaemon(True)
    self.thread.start()
  
  # Start Tunnning
  def __run(self):
    wx.CallAfter(self.AfterRun)
    self.t.StartTune()
    self.SetStatusText("Tunning Complete...")

  # Free GUI
  def AfterRun(self):
    pass
  
  # Stop Tuner
  def OnStop(self, event):
    self.t.StopTune()
    self.TuneButton.Enable(True)
    self.StopButton.Enable(False)
    print "Stoped!"

  (.....)
--
View this message in context: http://www.nabble.com/GUI-crashing-problem-help-tp23503108p23503108.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Adriann wrote:

Hy!
I have a problem concerning my implemented GUI, that is the program
sometimes stops and crashes the GUI and closes the windows. I get an error
like this : python: ../../src/xcb_lock.c:77: _XGetXCBBuffer: Assertion
`((int) ((xcb_req) - (dpy->request)) >= 0)' failed.Aborted

Any help is greatly appreciated!
Here is part of the code:

Googling "_XGetXCBBuffer: Assertion" seems to indicate that it's a threading issue, which is what I figured. I don't see anything obvious in your code, but I don't do plotting either. I don't see where you stop the daemon...maybe that is the issue? Or maybe there's another location in code you didn't show that is trying to access the GUI's main loop from a thread. That would cause this sort of thing too.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Hello,

Hy!
I have a problem concerning my implemented GUI, that is the program
sometimes stops and crashes the GUI and closes the windows. I get an error
like this : python: ../../src/xcb_lock.c:77: _XGetXCBBuffer: Assertion
`((int) ((xcb_req) - (dpy->request)) >= 0)' failed.Aborted

Any help is greatly appreciated!
Here is part of the code:

<snip>

   \#TUNNING INTERFACE

   \#               Prepare to Start Tunning
   def OnTune\(self,event\):
           self\.TuneButton\.Enable\(False\)
           self\.StopButton\.Enable\(True\)
           self\.SetStatusText\(&quot;Tunning\.\.\.&quot;\)
           self\.t = Tuner\.Tuner\(self\)
           self\.thread = threading\.Thread\(target=self\.\_\_run\)
           self\.thread\.setDaemon\(True\)
           self\.thread\.start\(\)

   \#               Start Tunnning
   def \_\_run\(self\):
           wx\.CallAfter\(self\.AfterRun\)
           self\.t\.StartTune\(\)
           self\.SetStatusText\(&quot;Tunning Complete\.\.\.&quot;\)

I am a little confused by the posted code (some stuff seems missing)
are there more than one classes code above?

Anyway the problem is quite clear, your making lots of GUI calls on a
thread that is not the main thread. The StartTune and SetStatusText
calls both modify the gui. You need to either wrap them in CallAfter
calls or post a message to the main thread to process them there
(which would make your thread not needed all together).

If you need to do some long running task in the StartTune method you
should refactor it to have all the gui updates done on the main thread
and the other business can be done on the worker thread.

See:
http://wiki.wxpython.org/Non-Blocking%20Gui
http://wiki.wxpython.org/LongRunningTasks

For more information about using threads to interact with the UI.

Cody

···

On Tue, May 12, 2009 at 9:56 AM, Adriann <adrian.david@ua.pt> wrote:

Thank you guys for the help. Indeed the problem was that i was not updating
the plot in the main thread. I have used LongRunningTasks document advices
and now my program is working.
Thanks again,
Adrian

···

--
View this message in context: http://www.nabble.com/GUI-crashing-problem-help-tp23503108p23522063.html
Sent from the wxPython-users mailing list archive at Nabble.com.