python多线程启动程序

python Threading模块

#coding=utf-8
import threading
import os

#创建启动后台服务
def djangoStart(func):
	#借用os运行启动服务命令(把后台注册成服务)
    os.system(r"net start PServer")
#创建启动前台服务
def nginxStsrt(func):
	#借用os运行启动服务命令(把前台注册成服务)
     os.system(r"net start HServer")
#启动浏览器
def chromeStart(func):
	#借用os运行启动浏览器命令
     os.system(r"start chrome.lnk")
def player(name):
    if name == 'MSEDBServer':
        djangoStart(name)
    else:
        if name == 'NginxServer':
            nginxStsrt(name)
        else:
			if name == 'chromeHtml':
				chromeStart(name)
			else:
				print 'error: The format is not recognized!'


list = ['MSEDBServer','NginxServer','chromeHtml']

threads = []
files = range(len(list))

#创建线程
for i in files:
    t = threading.Thread(target=player,args=(list[i],))
    threads.append(t)

if __name__ == '__main__': 
    #启动线程
    for i in files:
        threads[i].start() 
for i in files:
	threads[i].join()

你可能感兴趣的:(python多线程启动)