Fwd: Problem with threads in python????????

castironpi at gmail.com castironpi at gmail.com
Wed Feb 27 03:56:43 CET 2008


On Feb 26, 7:56 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Tue, 26 Feb 2008 01:46:48 -0200, Manikandan R <mani.ag... at gmail.com>  
> escribió:
>
> > Hai,
>
> >           Is it possible to share a single variable between multiple
> > threads. For eg:
>
> > Class A:
> >          thread_init()
>
> >        def run():
> >               fun1()
>
> > def fun():
> >  ........ assume some arithmatic operation is going on according to the
> > input given and each fun will *give different output*
> > .........
>
> Store the result inside the thread object; that is, in run, self.result =  
> fun1(...)
>
> > Now 10 Thread will be running and each thread will have there individual
> > output.
>
> >        Here is the problem now i want the sum of output of all the  
> > function.
>
>  From your code I imagine you have a list of Thread instances;
>
> global_result = sum([t.result for t in list_of_threads])
>
> --
> Gabriel Genellina

You can always hash the thread id: results[get_ident()]= result.



More information about the Python-list mailing list