import argparse, json, os, subprocess, sys, time FIRST = ["Nikita", "Alex", "Marta", "Ivan", "Sofia", "Leo", "Anna", "Mark", "Julia", "Daniel"] LAST = ["Reform", "Stone", "Novak", "Petrov", "Weber", "Kane", "Lopez", "Bright", "Fischer", "Miller"] def main(): ap = argparse.ArgumentParser() ap.add_argument("--start", type=int, default=10) ap.add_argument("--n", type=int, default=3) ap.add_argument("--workers", type=int, default=2) ap.add_argument("--base-port", type=int, default=9270) a = ap.parse_args() py = sys.executable pending = list(range(a.start, a.start + a.n)) running = [] # (proc, port, idx) def launch(idx, port): email_addr = "baradok609+fr%d@gmail.com" % (100 + idx) first = FIRST[idx % len(FIRST)]; last = LAST[idx % len(LAST)] cmd = [py, "C:/Users/User/tmp/framer/framer_one.py", "--email", email_addr, "--first", first, "--last", last, "--port", str(port), "--idx", str(idx)] env = dict(os.environ); env.pop("PYTHONPATH", None) env["PYTHONIOENCODING"] = "utf-8" logf = open("C:/Users/User/tmp/framer/log_%d.txt" % idx, "w", encoding="utf-8") pr = subprocess.Popen(cmd, env=env, stdout=logf, stderr=subprocess.STDOUT) print("[wave] launch idx=%d port=%d %s" % (idx, port, email_addr), flush=True) return pr, port, idx ports = list(range(a.base_port, a.base_port + a.workers)) free = ports[:] while pending or running: while pending and free: idx = pending.pop(0); port = free.pop(0) running.append(launch(idx, port)) time.sleep(3) for item in list(running): pr, port, idx = item if pr.poll() is not None: print("[wave] done idx=%d rc=%s" % (idx, pr.returncode), flush=True) running.remove(item); free.append(port) print("[wave] all done", flush=True) if __name__ == "__main__": main()