'How to run loop's iterations simultaneously?

I want to run my specific fragment of code in the same time. Problem is I don't know how many iterations going to be performed. Let's say that code's running and script knows there will be 16 iterations. These iterations (opening new subprocesses with object creating) I want to be run in the same time. How to make it?

fragment of first script

for x in range(pteses_size):
    client = subprocess.Popen(f'python api_alone.py {x}',
                          creationflags=CREATE_NEW_CONSOLE,
                          stderr=PIPE)
    print(client.pid)
    stderr = client.communicate()
    print(stderr)

fragment of second script (these I want to be ran in the same time so they're going to be calculated simultaneously

class API:
 # class content

api = API(sys.argv[1])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source