Python thread
Aahz Maruch
aahz at panix.com
Tue Jan 30 13:51:45 EST 2001
In article <95712k$g0j$1 at nnrp1.deja.com>, <golgo__13 at my-deja.com> wrote:
>
>Python thread document sucks! It all seems to just handwave the
>issue by saying it's close to Java thread model, but since I do
>not know it, it's not very useful.
Check out http://starship.python.net/crew/aahz/ for a bit more help.
>Anyway, I need to do something very simple, and I hope someone can
>help me. Basically I need to launch four threads and combine the
>result. One is CPU intensive and the other threeo are IO
>intensive and it needs no communication between. Right now it's
>done in linear way like so:
>a=funcA()
>b=funcB()
>c=funcC()
>d=funcD()
>e=a+b+c+d
>
>How can I get funcA(),funcB(),funcC() and funcD() started all at the
>same time?
You'll need to do something like this:
threads = []
threads.append(A())
threads.append(B())
threads.append(C())
threads.append(D())
for thread in threads:
thread.start()
total = 0
for thread in threads:
thread.join()
total += thread.result
(A(), B(), C(), and D() create class instances, subclassing
threading.Thread().)
--
--- Aahz (Copyright 2001 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
"People sometimes focus too much on the fact of communication rather than
the substance of communication." --Dave Morton
More information about the Python-list
mailing list