Alan Kennedy alanmk at
Tue Nov 11 18:08:48 CET 2003

[Zunbeltz Izaola]
> I want to know if it is posible to do this CHANGE of threads.

It is not possible to "switch" execution between threads like this:
the whole point of threads is that there multiple execution contexts
operating in parallel.

Once a thread has been started, it must run all the way through until
it's execution terminates naturally. You cannot even raise exceptions
in one thread from another thread.

What you *can* do is communicate information between threads. This is
most often done by using a Queue object, which you can read about here

So a good design pattern for what (I think) you're trying to do is to
devise a class/object which represents the work to be done, and send
that "work object" back and forth on the Queue between the threads.
This way, it "appears" that the work is actually moving between
threads. When there is no work for a thread to do, it is blocked in a
Queue.get call, waiting for something to do. But it does not "go

Of course, this is just one way to do it: another poster suggested
another excellent approach: co-routines. 


alan kennedy
check http headers here:
email alan:    

More information about the Python-list mailing list