I have a simple example problem that I am struggling with in Python. I am using multiprocess to execute an example where the function "Thread_Test()" will generate a uniform array of random numbers over the interval of 0 to 1, with "Sample_Size" number of data points in the array. Once I get this example down, I plan on generating multiple copies of the process in an attempt to accelerate code execution and then I will be putting a much more complex set of calculations in Thread_Test(). This example works fine as long as I keep the Sample_Size below 9,000. The execution time increases as I increase the Sample_Size from 10 to 8,000, but at 8,000 the code only takes 0.01 seconds to execute. However, as soon as I increase the Sample_Size to 9,000, the code just goes on in execution forever and never finishes the calculation. What is causing this?
from multiprocessing import Process, Queue
import queue
import random
import timeit
import numpy as np
def Thread_Test(Sample_Size):
q.put(np.random.uniform(0,1,Sample_Size))
return
if __name__ == "__main__":
Sample_Size = 9000
q = Queue()
start = timeit.default_timer()
p = Process(target=Thread_Test,args=(Sample_Size,))
p.start()
p.join()
result = np.array([])
while True:
if not q.empty():
result = np.append(result,q.get())
else:
break
print (result)
stop = timeit.default_timer()
print ('{}{:4.2f}{}'.format("Computer Time: ", stop-start, " seconds"))