Python:多线程发起请求

请求函数

def s3_put_file(fileKey):
    print u'用例开始:'
    currentFile = test_currentFile_730kb
    # S3 PUT上传文件
    date = get_utctime()
    rq = s3FileOp('PUT', fileKey, test_ak,  test_sk, test_bucket, date, test_s3_url, currentFile)
    if rq.status_code != 200:
        print u'Error!',fileKey
View Code

并发请求:

    def test_call_thread_50_730kb_file(self):
        print u'用例开始:'
        current_time = getUnixTime()
        name_list =[]
        for i in range(3000000):
            name_list.append('s3_put_730k_' + str(i+100001))
        start_time = time.time()
        pool = threadpool.ThreadPool(50)
        requests = threadpool.makeRequests(s3_put_file, name_list) 
        [pool.putRequest(req) for req in requests] 
        pool.wait() 
        print '%d second'% (time.time()-start_time)
View Code
每天努力一点,每天学习一点。 Keep Moving...
原文地址:https://www.cnblogs.com/channy14/p/14737928.html