Help doing simple threading

Andreas Jung andreas at
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
Digital Creations -,

More information about the Python-list mailing list