Question on threads
Steve Holden
steve at holdenweb.com
Fri Apr 11 15:29:09 EDT 2008
Jonathan Shao wrote:
> Hi all,
>
> I'm a beginner to Python, so please bear with me.
>
> Is there a way of guarenteeing that all created threads in a program are
> finished before the main program exits? I know that using join() can
> guarentee this, but from the test scripts I've run, it seems like join()
> also forces each individual thread to terminate first before the next
> thread can finish. So if I create like 20 threads in a for loop, and I
> join() each created thread, then join() will in effect cause the threads
> to be executed in serial rather than in parallel.
>
No it won't, as in fact there is no mechanism to force a thread to
terminate in Python. When you join() each created thread the main thread
will wait for each thread to finish. Supposing the longest-lived thread
finished first then all others will immediately return from join().
The only requirement it is imposing is that all sub-threads must be
finished before the main thread terminates.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list