多线程同时启动多个应用程序

# 同时启动多个可执行程序,可以传入命令行参数。

import os
import threading
import random
import time

def start_process():
    startcmd = r'a.exe uname=xxx;meeting=1;pwd=%s' % random.randint(100, 999999)
    os.system(startcmd)

def killall_process():
    killallcmd = r'taskkill /f /t /im "a.exe"'
    os.system(killallcmd)

def start_num(num):
    while num > 0:
        num -= 1
        t1 = threading.Thread(target = start_process)
        t1.start()

while True:
    flag = int(raw_input('0:exit, 111:killall, others:continue:'))
    if (flag == 0):
        break
    elif(flag == 111):
        killall_process()
    elif(flag <= 50):
        start_num(flag)
    else:
        continue
    

你可能感兴趣的:(多线程同时启动多个应用程序)