• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现的多线程http压力测试代码

Python实现的多线程http压力测试代码

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python3 多线程,python 多线程,python多线程编程,python 线程,python多线程实例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python实现的多线程http压力测试代码。分享给大家供大家参考,具体如下:

# Python version 3.3
__author__ = 'Toil'
import sys, getopt
import threading
def httpGet(url, file):
  import http.client
  conn = http.client.HTTPConnection(url)
  conn.request("GET", file)
  r = conn.getresponse()
  #print(r.getheaders())
  while not r.closed:
    r.read(200)
  conn.close()
def Usage():
  print('''
  Options are:
  -c concurrency Number of multiple requests to make
  -u host     The host
  -f file     File on web
  Example: httpget.py -c 100 -u www.example.com -f /
  ''')
if __name__ == '__main__':
  opts, args = getopt.getopt(sys.argv[1:], "hc:u:f:")
  global u, c, f
  for op, value in opts:
    if op == '-c':
      c = int(value)
    elif op == '-u':
      u = value
    elif op == '-f':
      f = value
    elif op == '-h':
      Usage()
      sys.exit(0)
    else:
      sys.exit(0)
  threads = []
  times = c
  print('Test for ', u, f)
  print('waiting...')
  for i in range(0, times):
    t = threading.Thread(target=httpGet(u, f))
    threads.append(t)
  for i in range(0, times):
    threads[i].start()
  for i in range(0, times):
    threads[i].join()

</div>

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python URL操作技巧总结》、《Python Socket编程技巧总结》、《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python实现的多线程http压力测试代码
  • 深入理解 Python 中的多线程 新手必看
  • python 简单的多线程链接实现代码
  • python 简单的多线程链接实现代码
  • 举例讲解Python编程中对线程锁的使用
  • Python实现简单多线程任务队列
  • Python实现快速多线程ping的方法
  • Python3中多线程编程的队列运作示例
  • Python中尝试多线程编程的一个简明例子

相关文章

  • 使用Python操作Elasticsearch数据索引的教程
  • 分享一个常用的Python模拟登陆类
  • Python 错误和异常小结
  • Python守护进程用法实例分析
  • 详解Python的Flask框架中的signals信号机制
  • python实现多线程的两种方式
  • 如何将python中的List转化成dictionary
  • 用Python实现命令行闹钟脚本实例
  • Python获取apk文件URL地址实例
  • python脚本实现查找webshell的方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 巧用python和libnmapd,提取Nmap扫描结果
    • Python数据类型详解(二)列表
    • 详解Python的Flask框架中的signals信号机制
    • 编写Python脚本来获取Google搜索结果的示例
    • Python实用日期时间处理方法汇总
    • python常用函数详解
    • 使用Python的Twisted框架构建非阻塞下载程序的实例教程
    • Python3实现将文件树中所有文件和子目录归档到tar压缩文件的方法
    • Python深入学习之闭包
    • Windows下Python的Django框架环境部署及应用编写入门

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有