黑松山资源网 Design By www.paidiu.com
可修改变量thread_count指定最大的并发数量,即线程的数量。
完成之后,打印输出失败的次数,以及开始时间和结束时间,单位是毫秒。
主要是学习一下Python,仅供参考。
#!/usr/bin/python3 import sys, time, json, _thread import http.client, urllib.parse thread_count = 100 #并发数量 now_count = 0 error_count = 0 begin_time = '' lock_obj = _thread.allocate() def test_http_engine(): global now_count global error_count global thread_count global begin_time conn = None if now_count == 0: begin_time = int(round(time.time() * 1000)) try: conn = http.client.HTTPConnection("192.168.1.1", 80) conn.request('GET', '/') response = conn.getresponse() data = response.read() print (data) if json.dumps(response.status) != '200': error_count += 1; print ('error count: ' + str(error_count)) sys.stdout.flush() now_count += 1 if now_count == thread_count: print ('### error count: ' + str(error_count) + ' ###') print ('### begin time : ' + str(begin_time)) print ('### end time : ' + str(int(round(time.time() * 1000)))) except Exception as e: print (e) finally: if conn: conn.close() def test_thread_func(): global now_count global lock_obj cnt = 0 lock_obj.acquire() print ('') print ('=== Request: ' + str(now_count) + ' ===') cnt += 1 test_http_engine() sys.stdout.flush() lock_obj.release() def test_main(): global thread_count for i in range(thread_count): _thread.start_new_thread(test_thread_func, ()) if __name__=='__main__': test_main() while True: time.sleep(5)
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- 【原神手游】5.1版本更新维护预告
- 李锦华.1987-日与夜(LP版)【SOLO】【WAV+CUE】
- 伍珂玥.2014-伍珂玥【湾彩星辰】【FLAC分轨】
- 吕方.2001-旧情人·老情歌精选2CD【华纳】【WAV+CUE】
- 《星际战士2》¥219,《100% 鲜橙汁》¥7
- 手办鉴赏室:少女眼神颇有杀意!连衣裙勾勒傲人轮廓
- 未来可期的二次元大逃杀游戏——《白厄战境》简评
- 炉石传说死亡骑士卡组怎么搭配 死亡骑士最新卡组2024推荐
- 魔兽世界地下堡珍玩怎么升级 地下堡珍玩升级方法攻略分享
- 魔兽世界怎么获得泽克维尔的残血珍玩 泽克维尔的残血珍玩获取方式
- FrankSinatra-StrangersInTheNight(1966Jazz)[Flac24-96]
- 大原樱子《CAMON+5thAnniversaryBest~》2CD[24-96]flac
- Isgaard2003-GoldenKey(LimitedEdition)【WAV+CUE】
- 《合金装备3RE》伊娃定妆照公布:没被政确太好了
- 石家庄新增《黑神话:悟空》墙绘:小狐狸萍萍