Python 3.4 Multiprocessing, code does not progress past loop (containing Queue)
<p>I have written a bit of code to test out multiprocessing before I implement in other code. The main code sends a number to the other program (running on another core). That program increments and returns the number. main code increments and returns the value again. All works well, but the loop in the main program, which is a while time &lt; Timeout form, is never exited. Seems simple enough to me, but it never exists the loop. I wondered if it was hanging when no value is returned (.get() ), but I have tried 'try:', and making the timeout very short and the loop huge. Any suggestions what is going on?</p>

<p>The code is running on Windows7, and will eventually run on a Raspberry Pi 2.</p>

<p>Main program</p>

<pre><code>import multiprocessing as mp
import multi_processing_slave as MPS
from time import perf_counter as TimeIs

if __name__ == "__main__":
    print("Hello World")
    mp.set_start_method("spawn")
    q = mp.Queue()
    r = mp.Queue()
    p = mp.Process(target = MPS.foo, args = (q, r))
    p.start()
    ThisVar = 0
    Timer = TimeIs() + 2
    while TimeIs() &lt; Timer - 1: pass
    print("time remaining is", Timer - TimeIs())
    while TimeIs() &lt; Timer:
        #try:
        r.put(ThisVar)
        #except: pass
        #try:
        ThisVar = int(q.get()) + 1
        #except:
        #r.put(ThisVar)
        print("master ThisVar", ThisVar, "and time remaining is", round(Timer - TimeIs(), 4))
    #p.join()
    #p.close()
    p.terminate()
    print("at end, ThisVar is", ThisVar, "and", Timer - TimeIs(), "seconds remaining")
</code></pre>

<p>Slave program named multi_processing_slave</p>

<pre><code>def foo(q, r):
    for i in range(100):
        ThisVar2 = r.get() + 1
        q.put(ThisVar2)
        print("foo value", ThisVar2)
    print("foo has finished")
    return
</code></pre>