import subprocess from multiprocessing import Process import os os.environ['CUDA_VISIBLE_DEVICES'] = '-1' def run_consumer_clustering(): proc = subprocess.Popen("python consumer_clustering.py", shell=True) print(proc.pid) proc.communicate() def run_consumer_merge_clustering(): proc = subprocess.Popen("python consumer_merge_clustering.py", shell=True) print(proc.pid) proc.communicate() if __name__ == '__main__': execs = [] n_pro = 5 for pro in [run_consumer_clustering ,run_consumer_merge_clustering]: for i in range(n_pro): ex = Process(target=pro, args=()) execs.append(ex) ex.start() for exe in execs: exe.join()