程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Run Linux scripts through python, and test the performance of the multi-threaded test machine

編輯:Python

ad locum local.sh Is the script to test , Voice to text for voice processing

1python call linux Script

#/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')

Multithreading python Call script

#/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(" Start thread "+self.name)
a = RunCmd()
for i in range(10):
a.cmd_run('sudo bash local.sh')
print(" End thread "+self.name)
threads = []
num=100
names = locals()
# Create a new thread 
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()

Here, you can implement multithreading to run together , It's not locked here either


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved