I have an array filled with commands and I want to execute all of the commands at the same time.
So far I have:
import threading
...
def MyThread0():
exec commandArray[0]
def MyThread1():
exec commandArray[1]
t1 = threading.Thread(target=MyThread0(), args=[]).start()
t2 = threading.Thread(target=MyThread1(), args=[]).start()
While this may still be acceptable if there are only two threads (it seems to work, at least), it certainly is not if the length of the commandArray is unknown at runtime. How do I do this efficiently for x number of threads?
PS: It is entirely possible that all of this is junk as I'm new to multithreading. Constructive criticism is highly appreciated.
()after the functions' names when creating the threads. That will call the function before the line is evaluated.