[SciPy-dev] gui_thread and chaco under Linux

Pearu Peterson pearu at scipy.org
Mon Oct 6 10:34:33 EDT 2003


Hi,

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

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

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

When importing chaco.wxplt from the same thread that imported 
wxPython (by inserting `import chaco.wxplt` just after wxPython import in 
gui_thread/gui_thread_guts.py), then we have this:

>>> import gui_thread
>>> gui_thread.start()
<Importing wxPython...  done.>
>>>
>>> from chaco.wxplt import *
>>> 

but now trying to make a simple plot fails with python hang:

>>> plot([1,2])
Xlib: unexpected async reply (sequence 0x7a)!

Again, the reason for this failure is that the above plot function was 
called from the main but wrong thread. 

For example, inserting also `chaco.wxplt.plot([1,2])` to
gui_thread/gui_thread_guts.py will result a working wx plot window as well
as working python prompt. This example worked because the plot function
was called from the right (secondary) thread.

While having chaco imports in gui_thread/gui_thread_guts.py can be 
acceptable but I have failed to figure out how to force calling plot 
function from the prompt (that runs under the main thread) so that it will 
be executed in the second thread (that imported wxPython and chaco).

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

The following solutions come into my head:
1) Introduce a wrapper around wxPython module that transforms all
accesses to wxPython data from the main thread to the secondary thread 
(that imports wxPython). I think this can be achieved without 
touching chaco at all through similar hooks that are used in ppimport.

2) Import wxPython from the main thread and create an interactive prompt 
thread from wxPython app. This would require implementing a prompt very 
similar to PyCrust but that would have I/O from the terminal.

Both solutions would require a lot of work and I would hope that there
would be a simpler solution. For example, getting gui_thread to work
correctly under X.

Other thoughts?

Regards,
	Pearu



More information about the SciPy-Dev mailing list