![]() If process.poll() is not None: # the process has finished ![]() Running_processes = list(islice(processes, max_workers)) # start new processesįor i, process in enumerate(running_processes): ![]() Processes = (Popen(cmd, shell=True) for cmd in commands) Max_workers = 2 # no more than 2 concurrent processes You could limit the number of concurrent child processes without using a thread/process pool: from subprocess import Popen This answer demonstrates various techniques to limit number of concurrent subprocesses: it shows multiprocessing.Pool, concurrent.futures, threading + Queue -based solutions. Print("%d command failed: %d" % (i, returncode)) Pool = Pool(2) # two concurrent commands at a timeįor i, returncode in enumerate(pool.imap(partial(call, shell=True), commands)): To limit number of concurrent commands you could use that uses threads and provides the same interface as multiprocessing.Pool that uses processes: from functools import partial ![]() You don't need threads to run subprocesses in parallel: from subprocess import Popen ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |