About object reference and threads

Laura Creighton lac at strakt.com
Mon Jan 27 14:31:39 EST 2003


> Laura Creighton wrote:
> > and a Thread (made like this)
> > 
> >        self.thread1 = threading.Thread(target=self.workerThread1)
> 
> The thread shares the same members as self when using target like
> that? I wanted a subclass of Thread with its own run method. Doing it
> like the example said would mean the self.queue would refer to the
> parent's queue member. Doing it the way I wanted, self.queue would
> refer to the thread's queue. Am I correct? Is one way better than the
> other?

The whole point of the queue is to let the different threads communicate.
This means that it has to be the _same_ queue.  If the parent's queue,
and each worker's queue are different, then writing things to them
will not communicate anything.  You will just get a lot of full queues.

It is possible that what you want is two queues, a back queue to
communicate back to the parent.

> 
> I tried what Peter said and it seems to work but I can't realy test it
> without finishing another part of the program.
> 
> Thank you.
> -- 

You're welcome.

> http://mail.python.org/mailman/listinfo/python-list

Laura Creighton





More information about the Python-list mailing list