Python 压力测试脚本


目的是写个脚本,起多线程去call一个接口,来测试一个并发问题。
实现方案是将接口做到了一个页面中,用python的http get请求来访问查询。
 
import urllib

import threading
from time import ctime,sleep



def t1(func):
  for i in range(10):
    f=urllib.urlopen("http://www.mystation.com/myinterface.html?param=value")
    s=f.read()
    print "round:%s, tread number:%s, returnValue:%s,time:%s" % (i, func, s, ctime())
    sleep(1)


if __name__ == '__main__':
  threads=[]
  for i in range(100):
    name = "t%s" % (i)
    name = threading.Thread(target=t1,args=(i,))
    threads.append(name)


  for t in threads:
    t.setDaemon(True)
    t.start()
  t.join()

 


相关内容

    暂无相关文章

评论关闭