[SciPy-dev] gui_thread and chaco under Linux

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Tue Oct 7 09:25:44 CDT 2003


Hi Pearu,

>>>>> "PP" == Pearu Peterson <pearu at scipy.org> writes:

    PP> I have struggling with getting chaco to work under Linux.
    PP> Currently the following happens:

    >>>> import gui_thread gui_thread.start()
    PP> <Importing wxPython...  done.>
    >>>>
    >>>> from chaco.wxplt import *
    PP> Xlib: unexpected async reply (sequence 0x68)!

    PP> After some research I found that the above failure occurs
    PP> because wx functions are not called from the same thread that
    PP> imported wxPython, first this happens in
    PP> traits/wxtrait_sheet.py.

[snip]

    PP> Somehow I am getting a feeling that the gui_thread concept is
    PP> just not working under Linux (or any Unixes that run under X)
    PP> because X is not thread safe and therefore there is a
    PP> condition that wxPython must be imported and used strictly
    PP> within the same thread.  Please, correct me if I am wrong on
    PP> this!

Well, gui_thread does work under Linux.  For example, this works for
me:

In [1]: import gui_thread
In [2]: gui_thread.start()
<Importing wxPython... i done.>
>>>
In [3]: import scipy.plt as plt
In [4]: p = plt.plot([1,4,9])

I think its just that wxplt is not using gui_thread and is currently
pure wxPython code.  As you have rightly discovered the way to
chaco-on-interpreter-heaven is to call all wxPython related functions
from another thread and this thread must be the first to import
wxPython.  To use gui_thread you need to 'register' a class with it.
gui_thread then returns a massaged class wraps around the actual class
that the actual functions are called in the right thread.  It also
tries to handle attribute access safely.  However, this is from memory
having hacked on gui_thread about two years ago and a few things might
have changed.  Anyway, the way to register a class with gui_thread is
to do the following:

wrapped_class = gui_thread.register(some_wx_python_class)

Then you create wrapped_class instances as you would create
some_wx_python_class and it should work (in theory).  I can't test
this because I cannot run chaco anymore.  kiva no longer builds under
gcc 2.95.4. :(

Admittedly, the gui_thread approach is a hack and has limitations but
it used to work pretty OK.  Eric was talking about a better approach
that IIRC is similar to your approach (1).  As you notice its a
non-trivial job and AFAIK no one has yet had a stab at it.


cheers,
prabhu


More information about the Scipy-dev mailing list