여러 응용 프로그램을 시작하려면 스레드를 사용하는 것이 좋습니다.
shellcommands=("notepad.exe",
"calc.exe",
"mspaint.exe")
import os
import sys
import time
import datetime
import threading
import subprocess
class ThreadClass(threading.Thread):
# Override Thread's __init__ method to accept the parameters needed:
def __init__ (self, command):
self.command = command
threading.Thread.__init__ (self)
def run(self):
now = datetime.datetime.now()
print "%s %s %s \n" % (self.getName(), self.command,now)
try:
subprocess.call(self.command, shell=True)
except Exception, err:
print "ERROR: %s\n" % str(err)
for cmd in shellcommands:
t = ThreadClass(cmd)
t.start()
sys.exit()
왜이 경우'서브 프로세스 '를 사용하지 않습니까? –
'subprocess'는'multiprocessing'을 사용하는 프로세스간에 데이터를 공유해야하는 경우를 제외하고 훨씬 쉽게 만듭니다. – tMC