[vtkusers] Threading with vtkRenderWidget and Python?

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Wed Jan 8 03:43:48 EST 2003


hi,

>>>>> "UP" == Utsav Pardasani <pardasaniman at yahoo.com> writes:

    UP> Hello friends.  I would like to make a multithreaded
    UP> application with VTK and python. Is it able to work?  I
    UP> attempted to do a simple example and it is unable to
    UP> execute. Can somebody verify it?

[snip]

The way you have implemented the threading is that Tk's mainloop is
running as the main thread and you are then invoking vtk related
things in a separate thread.  This will usually lead to disastrous
results the best case being you will see nothing on screen and the
worst case being your X session will crash.

The way I find it convenient to do things with Python, multiple
threads and VTK is to put Tk and VTK into one thread (the main thread
of execution -- we'll call it main) and then do your application
specific stuff (like computations etc. -- lets call it thread1) in a
separate thread.  Then to invoke a function from thread1 in main you
make sure that main executes the function by asking Tkinter to make
the call.  Something like so:

 root = Tk()

 # now from your thread1 do the following:
 root.after(1, function, args)

Where function is the VTK/Tkinter specific function you want to call
from thread1.  Alternatively, add a function thats part of your main
thread of execution to invoke the function for you.  root.after is
just a convenient way of doing that from Tkinter.  Basically you have
to ensure that all the GUI/VTK commands originate from the same thread
that they (GUI and VTK) are running in.

This should work reliably.

cheers,
prabhu



More information about the vtkusers mailing list