Help doing simple threading
andreas at digicool.com
Wed Mar 14 13:54:12 CET 2001
>I am trying to learn how to use threads. I want multiple threads to be
>able to communicate. I thought that threads started by a common process
>would share globals in that module. I want thread to be able to store
>esults in a common array. However the following returns all zeros, so
>clearly I am not passing anything back to the top level list 'z'. Can
>someone tell me how I should be passing things back from threads?
Your code has several problems:
a) You don't synchronize your main thread with the threads you start.
That means your main thread continues running BEFORE the
started threads make any work.
b) Modifying shared resources within threads is dangerous. Think
about using locks to get rid of this problem.
c) Try the threading module. It gives you a better control and programmer
interface to work with thread in Python.
Andreas Jung (andreas at digicool.com)
Digital Creations - www.digicool.com, www.zope.org
More information about the Python-list