• python通过多线程去调用接口注册新用户【杭州多测师】【杭州多测师_王sir】


    #!/usr/bin/python3
    import threading
    import time
    import json
    import requests
    class myThread (threading.Thread):
        def __init__(self, threadID, name, delay):
            threading.Thread.__init__(self)
            self.threadID = threadID
            self.name = name
            self.delay = delay
    
        def register(self,count):
            """
            '''定义一个注册接口、循环进行注册'''
            :param count: 这个控制需要注册多少次
            :return:
            """
            mobile = 15311112222
            for i in range(count):
                url = 'https://m.snt-art.com/api/login'
                data ={"code": "123456",
                       "loginType": 1,
                       "mobile": str(mobile+i),
                       "password": "abc123456",
                       "invitationCode": ""}
                headers = {"Content-Type":"application/json"}
                response = requests.post(url,data=json.dumps(data),headers=headers)
                print(response.text)
    
        def run(self):
            print ("开启线程: " + self.name)
            # 获取锁,用于线程同步
            threadLock.acquire()
            self.register(10)
            # print_time(self.name, self.delay, 3)
            # 释放锁,开启下一个线程
            threadLock.release()
    
    def print_time(threadName, delay, counter):
        while counter:
            time.sleep(delay)
            print ("%s: %s" % (threadName, time.ctime(time.time())))
            counter -= 1
    
    threadLock = threading.Lock()
    threads = []
    
    # 创建新线程
    thread1 = myThread(1, "Thread-1", 1)
    thread2 = myThread(2, "Thread-2", 2)
    
    # 开启新线程
    thread1.start()
    thread2.start()
    
    # 添加线程到线程列表
    threads.append(thread1)
    threads.append(thread2)
    
    # 等待所有线程完成
    for t in threads:
        t.join()
    print ("退出主线程")
  • 相关阅读:
    spring boot自动配置
    servlet类与Spring Controller类的关系
    Junit中的setup和teardown方法
    dependency的scope
    mapper的namespace
    mybatis缓存
    Ehcache(05)——缓存的查询
    Ehcache(04)——设置缓存的大小
    Ehcache(03)——Ehcache中储存缓存的方式
    Ehcache(02)——ehcache.xml简介
  • 原文地址:https://www.cnblogs.com/xiaoshubass/p/16650334.html
Copyright © 2020-2023  润新知