欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python+threading模塊對單個接口進(jìn)行并發(fā)測試

 更新時間:2019年06月25日 11:12:51   作者:夢四十九劍  
這篇文章主要為大家詳細(xì)介紹了Python+threading模塊對單個接口進(jìn)行并發(fā)測試,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Python threading模塊對單個接口進(jìn)行并發(fā)測試的具體代碼,供大家參考,具體內(nèi)容如下

本文知識點(diǎn)

通過在threading.Thread繼承類中重寫run()方法實(shí)現(xiàn)定制輸出結(jié)果

代碼如下

import requests
import threading
import sys, io
# 解決console顯示亂碼的編碼問題
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

class Mythread(threading.Thread):
 """This class customizes the output thu overriding the run() method"""
 def __init__(self, obj):
 super(Mythread, self).__init__()
 self.obj = obj

 def run(self):
 ret = self.obj.test_search_tags_movie()
 print('result--%s:\n%s' % (self.getName(), ret))
 

class Douban(object):
 """A class containing interface test method of Douban object"""
 def __init__(self):
 self.host = 'movie.douban.com'
 self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
 'Referer':'https://movie.douban.com/',
 }

 def get_response(self, url, data):
 resp = requests.post(url=url, data=data, headers=self.headers).content.decode('utf-8')
 return resp

 def test_search_tags_movie(self):
 method = 'search_tags'
 url = 'https://%s/j/%s' % (self.host, method)
 post_data = {
  'type':'movie',
  'source':'index'
 }
 resp = self.get_response(url=url, data=post_data)
 return resp
 
if __name__ == '__main__':
 douban = Douban()
 thds = []
 for i in range(9):
 thd = Mythread(douban)
 thd.start()
 thds.append(thd)

 for thd in thds:
 thd.join()

運(yùn)行結(jié)果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論