Help doing simple threading

David Bolen db3l at fitlinxx.com
Wed Mar 14 23:28:00 EST 2001


David Lees <deblNonOspammy at theworld.com> writes:

> Thanks, these comment were quite helpful.  The most serious error was
> 'a)'.  when I just put the main to sleep after starting up the threads
> it worked fine.  The problem was that I was printing out the array
> values, before all the threads finished executing.

If by sleep, you just mean you added something like time.sleep() with
a fixed value, then you're still at risk, depending on the performance
of the other thread executions.

You will need to use some sort of synchronization primitive to ensure
that the main thread waits long enough for each of the worker threads
to complete.  If you know you want to wait until the threads actually
complete execution and terminate, and if you use the higher level
Threading module, you can "join" on the threads to block until they
complete.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list