Communicating between threads
petr at kubanek.net
Fri Sep 28 21:49:00 CEST 2001
let's make it simple:
print "Starting threads"
self.seed = 0
self.seed = self.seed+1
print "Incremented - new value:"+str(self.seed)
print "Seed value: "+str(self.seed)
a = test()
You don't need any signals etc., simple make class and change value in it.
You are right with signal, it's performing randomly when more threads are
running. If you realy need sending signal, don't use threads, use fork.
fladak at rri.on.ca wrote:
> 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
> 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
> When I rotate the image in viewer 1, thread A in viewer 1 communicates to
> 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
> 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
> the main thread to have the signal handler called. Thus I can't use this
> 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.
> This message was sent using Endymion MailMan.
More information about the Python-list