美文网首页
python多线程练习

python多线程练习

作者: 铁甲依然在人间 | 来源:发表于2021-07-08 14:15 被阅读0次

接到一个需求看看单点服务器能承受多少并发,记录一下脚本

# -*- coding: utf-8 -*-
import requests
import threading
import time
class postrequests():
    def __init__(self):
        self.url = 'http://12xxxx'
        self.files = {'image_file':open(r'C:\Users\renfy\Pictures\7m.png','rb'),

                      #'image2_file':open(r'D:\image\Pictures\1.jpg','rb')
                      }
    def post(self):
        try:
            r = requests.post(self.url,files=self.files)
            print(r.text)
        except Exception as e:
            print(e)

def login():
    login = postrequests()
    return login.post()
if __name__ == '__main__':
    login()
try:
    i = 0
    # 开启线程数目
    tasks_number = 5
    print('测试启动')
    time1 = time.clock()
    while i < tasks_number:
        t = threading.Thread(target=login)
        t.start()
        i +=1
    time2 = time.clock()

    times = time2 - time1
    print(times/tasks_number)
except Exception as e:
    print(e)

相关文章

  • python多线程练习

    接到一个需求看看单点服务器能承受多少并发,记录一下脚本

  • GIL

    谈谈python的GIL、多线程、多进程 最近在看 Python 的多线程,经常我们会听到老手说:“python下...

  • Python多线程编程——多线程编程中的加锁机制

    如果大家对Python中的多线程编程不是很了解,推荐大家阅读之前的两篇文章:Python多线程编程——多线程基础介...

  • Python学习笔记-第10天:numpy模块以及Python的

    第十天 numpy模块介绍和使用 今天计划学习numpy模块以及Python的多线程编程,学习项目及练习源码地址:...

  • 5-线程(补充)

    Python多线程原理与实战 目的: (1)了解python线程执行原理 (2)掌握多线程编程与线程同步 (3)了...

  • Python_提高

    GIL全局解释器锁 描述Python GIL的概念, 以及它对python多线程的影响?编写⼀个 多线程抓取⽹⻚的...

  • Python程序员都知道的入门知识の八

    目录【Python程序员都知道的入门知识】 1. 多线程threading、Queue Python的多线程由th...

  • Python多线程实现生产者消费者

    1. Python多线程介绍 Python提供了两个有关多线程的标准库,thread和threading。thre...

  • 多线程

    Python多线程原理与实战 目的: (1)了解python线程执行原理 (2)掌握多线程编程与线程同步 (3)了...

  • Python多线程(上)

    前言 说起Python的多线程,很多人都嗤之以鼻,说Python的多线程是假的多线程,没有用,或者说不好用,那本次...

网友评论

      本文标题:python多线程练习

      本文链接:https://www.haomeiwen.com/subject/bhqtpltx.html