i wrote the following code, that runs a command using subprocess method, under 2 for loops,
import threading
import subprocess
def do (i,j):
subprocess.Popen(['python2.7 some_python_code.py {} {}'.format(i,j)],shell=True,stdout=subprocess.PIPE)
z=[]
for i in range (0,50):
for j in range (0,50):
t = threading.Thread(target=do, args=(i,j))
t.start()
z.append(t)
for t in z:
t.join()
the matter is that it suddenly starts a massive number of python process and eats the entire of my memory, how can i limit the number of threads ?
thanks.