wxPython on Linux and Windows

Good day !

I made a program that uses wxPython. It runs fine on Windows but crashes on Linux.
The error is 'Xlib: unexpected async reply'.

My program uses a thread to update the GUI components.

Is this a wxPython bug ?

yours truly,
Ivar

" Time is the fire in which we burn ... "

Nope--it's a bug in your program :wink:

One must not touch the GUI from auxiliary threads.

I think that this is in the FAQ.... If you want to do something to the
GUI from an auxiliary thread, you can do it indirectly via wxCallAfter.

···

On Mon, Jun 02, 2003 at 01:36:15PM +0800, Ivar N. Marohombsar wrote:

I made a program that uses wxPython. It runs fine on Windows but
crashes on Linux. The error is 'Xlib: unexpected async reply'.

My program uses a thread to update the GUI components.

Is this a wxPython bug ?

--
I wish that I could capitalise punctuation.
To place emphasis on the stop at the end of a sentence.

What does "wxCallAfter" do exactly? I can't find it in the
wxWindows/wxPython docs.

Bryan

···

On Mon, 2003-06-02 at 06:51, Joshua Judson Rosen wrote:

On Mon, Jun 02, 2003 at 01:36:15PM +0800, Ivar N. Marohombsar wrote:
>
> I made a program that uses wxPython. It runs fine on Windows but
> crashes on Linux. The error is 'Xlib: unexpected async reply'.
>
> My program uses a thread to update the GUI components.
>
> Is this a wxPython bug ?

Nope--it's a bug in your program :wink:

One must not touch the GUI from auxiliary threads.

I think that this is in the FAQ.... If you want to do something to the
GUI from an auxiliary thread, you can do it indirectly via wxCallAfter.

thanks for the info...but why does it works on Windows ?

···

----- Original Message -----
From: "Joshua Judson Rosen" <rozzin@geekspace.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Monday, June 02, 2003 1:51 PM
Subject: Re: [wxPython-users] wxPython on Linux and Windows

It's basically an asynchronous version of `apply'--
`wxCallAfter(func, argtuple)' queues a function-application to be
executed by the event-loop in the main/GUI thread.

If you check the archives of the mail-list, you'll find plenty of
discussion about it :wink:

···

On Mon, Jun 02, 2003 at 10:02:14AM +0100, bryan cole wrote:

What does "wxCallAfter" do exactly? I can't find it in the
wxWindows/wxPython docs.

--
"If it isn't source, it isn't software." --NASA

Ivar N. Marohombsar wrote:

thanks for the info...but why does it works on Windows ?

Because it happens to work on Windows due to different threading models. (I suppose that the Windows native GUI is thread-friendlier than GTK is.) The important point here is that calling GUI code directly from secondary threads cannot be guaranteed to work -- it *might* work sometimes on certain platforms, but will not work from every platform. Since there's no way to ensure that it'll work under an arbitrary platform, it's a very good idea to avoid doing this, on general principle.

Jeff Shannon
Technician/Programmer
Credit International

bryan cole wrote:

···

What does "wxCallAfter" do exactly? I can't find it in the
wxWindows/wxPython docs.

#----------------------------------------------------------------------------
_wxCallAfterId = None

def wxCallAfter(callable, *args, **kw):
     """
     Call the specified function after the current and pending event
     handlers have been completed. This is also good for making GUI
     method calls from non-GUI threads.
     """
     app = wxGetApp()
     assert app, 'No wxApp created yet'

     global _wxCallAfterId
     if _wxCallAfterId is None:
         _wxCallAfterId = wxNewEventType()
         app.Connect(-1, -1, _wxCallAfterId,
               lambda event: event.callable(*event.args, **event.kw) )
     evt = wxPyEvent()
     evt.SetEventType(_wxCallAfterId)
     evt.callable = callable
     evt.args = args
     evt.kw = kw
     wxPostEvent(app, evt)

#----------------------------------------------------------------------

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!