Suppose that there is a method receiving data from somewhere. In this method we should create three threads or a fixed number of threads. Every piece of received data will be assigned to a thread.
In other words, if you will receive 10 lists of data (Note that the number of data items not fixed and can't be known), the first list will be assigned to the first thread, the second list to the second thread, third list to the third thread and the fourth list will start over and assign to the first thread or to any available thread and like so.
So the only number we know is the number of the threads that they will running in that method.
Note that the three threads should be running in the same time. Once a thread becomes available or finishes its task it will get the next data item and process it.
This is what I am doing now but if I have 30 lists of data, 30 threads will be created which is terrible.
threads = []
for ip in ip_list:
for cmd in commands:
th = threading.Thread(target=test_ssh_conn(ip,cmd), args=(ip,)) # args is a tuple with a single element
th.start()
threads.append(th)
for th in threads:
th.join()