from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
import os,time,random,subprocess
def task(cmd):
print('%s is runing' %os.getpid())
sub = subprocess.Popen(cmd, shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sub.communicate()
return cmd
if __name__ == '__main__':
commlines = []
with open('./down_file.txt','r') as f:
for line in f.readlines():
commlines.append(line.strip('\n'))
executor = ProcessPoolExecutor(max_workers=10)
futures = []
for cmd in commlines:
future = executor.submit(task,cmd)
futures.append(future)
executor.shutdown(True)
print('+++>')
for future in futures:
print(future.result())