I want to call a function that takes a long time to execute(variable, from 0 to 300 sec.), it has to be executed as many times as there are lists in a json. How can I do it so that it executes three in parallel, for example?
To make it simpler the code in the explanation would be to call a function, this...
def f(x, j):
print(str(x*x)+" "+" "+str(j))
time.sleep(2)
j = 0
for i in range(10):
j += 1
f(i,j)
result
thread 1 : 0, 1
thread 2 : 1, 2
thread 3 : 4, 3
thread 1 : 9, 4
thread 2 : 16, 5
thread 3 : 25, 6
thread 1 : 36, 7
thread 2: 49, 8
thread 3: 64, 9
thread 1: 81, 10
Thread three could end before thread one, but I always want three runs.