Communicating between threads

fladak at rri.on.ca fladak at rri.on.ca
Fri Sep 28 20:54:53 CEST 2001


Does anyone know how to communicate between threads?  It might help if I
explained my application.

I have two instances of an application, written in python, running.  I refer to
the application as a "viewer".  Both instances have two threads.  The main
thread (I'll refer to it as thread A) handles the GUI events and the other
thread (I'll refer to it as thread B) communicates to the other viewer using
OmniOrb, an implementation of CORBA.  I'm trying to develop the code so that if
you rotate the image in one viewer, the image in the other viewer rotates.  

When I rotate the image in viewer 1, thread A in viewer 1 communicates to thread
B in viewer 2 and requests a rotation.  Since thread A handles all the GUI
events, I need some way to communicate this from thread B in viewer 2 to thread
A in viewer 2.  

I can't use IPC or uni-directional named pipes here because thread A is already
busy listening for events, so it can't listen on a pipe or a socket.

I also tried using signals but experienced some problems in Linux and Windows.
Under Linux, thread A which is the main thread registers the signal handler and
if you send a signal from a thread other than the main thread (in this case
thread B) the signal handler is not called.  You have to send the signal from
the main thread to have the signal handler called.  Thus I can't use this as
means to communicate between threads.  It seems that signals are meant as a way
to communicate between processes not threads.  I wrote a test program where I
sent a signal between threads and it didn't work.  Under Windows, the kill()
function which is used to send the signal just doesn't exist in python and many
of the signals like SIGUSR1 don't exist.

Does anyone have any suggestions?  Thanks. 

-Faruq

---------------------------------------------
This message was sent using Endymion MailMan.
http://www.endymion.com/products/mailman/






More information about the Python-list mailing list