Python global array with multiprocessing
<p>Please consider the following code:</p>

<pre><code>from multiprocessing import Process
import time

myArray = []

def myThread():
    counter = 0
    global myArray
    while True:
        myArray.append(counter)
        time.sleep(1)

counterThread = Process(target=myThread,)
counterThread.start()

while True:
    if len(myArray) &gt; 0:
        print "Success"
    else:
        print ":("
        print myArray   
    time.sleep(1)
</code></pre>

<p>I am unable to get my success message, and i'm not sure why, I keep receiving <code>:(</code> and my terminal printing an empty array. I thought making the array global would mean any changes made at <code>myThread()</code> level would be applied?</p>

<p>You are creating an second process, which has no access to data of the main process. You can use threading.Thread(target=myThread,), but you has to synchronize the access threading.Lock(), if you are using more than one thread. </p>

<p>You should terminate your thread, when you are finished and wait for the thread with athread.join().</p>

<p>See:
<a href="https://docs.python.org/2/library/threading.html" rel="nofollow">https://docs.python.org/2/library/threading.html</a></p>

python arrays multithreading global multiprocess