I have discovered that the problem goes away if I do not start the threads immediately:
I have to inject a delay
def spawnAWorker(i): printf("%s", i) #os.system('start cmd /K ' + workerCmd) threads = map(lambda i: threading.Thread(target=lambda: spawnAWorker(i)),range(0,2)) for t in threads: t.start()But, I see a problem here as well. If range is larger, say (0,100), I do not see all numbers printed. Some threads do not start.
I have to inject a delay
for t in threads: t.start() time.sleep (1) ## this sucks but some threads do not start if I launch them all at the same timeif I want all threads to start. I want more deterministic solution.