returning a value from a thread

Christopher T King squirrel at WPI.EDU
Wed Jul 14 12:52:01 EDT 2004


On Wed, 14 Jul 2004, Ken Godee wrote:

> I thought there was some sort of memory type container
> I could use...
> 
> ie. store value in memory from module3 and be able to
> read it from module1.
> 
> The closest I can think of is to pass a queue reference
> and stor values from module3 in the queue and then read them
> back while in module1.

Actually, any kind of container object would do: you could pass a list, 
dictionary, or class to the thread, and the thread could store its results 
in it.

A hackish method would be to pass the dictionary returned by locals() in 
module1 to the thread. This way the thread could set a value in module1 
directly.

Just don't forget to .join() on the thread in module1 before accessing the 
container object! (Assuming you're using threading) I just wish Python's 
.join() could return values, like pthread_join can.




More information about the Python-list mailing list