在這裡local.sh是要測試的腳本,為語音處理語音轉文字
#/usr/bin/env python
import subprocess
class RunCmd(object):
def cmd_run(self, cmd):
self.cmd = cmd
subprocess.call(self.cmd, shell=True)
#Sample usage
a = RunCmd()
for i in range(10):
a.cmd_run('bash local.sh')
#/usr/bin/env python
from re import S
import subprocess
class RunCmd(object):
def cmd_run(self, cmd):
self.cmd = cmd
subprocess.call(self.cmd, shell=True)
#Sample usage
# a = RunCmd()
# for i in range(10):
# a.cmd_run('bash local.sh')
# thread test
import threading
import time
class myThread (threading.Thread):
def __init__(self, threadID, name):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
def run(self):
print("開始線程"+self.name)
a = RunCmd()
for i in range(10):
a.cmd_run('sudo bash local.sh')
print("結束線程"+self.name)
threads = []
num=100
names = locals()
# 創建新線程
for i in range(num):
names['thread{}'.format(str(i))]=myThread(i,'thread-{}'.format(str(i)))
for i in range(num):
names['thread{}'.format(str(i))].start()
for i in range(num):
names['thread{}'.format(str(i))].join()
這裡就可以實現多線程一起運行,這裡也沒加鎖