当前位置:   article > 正文

python启多线程请求简单例子_python多线程处理请求

python多线程处理请求
# -*- coding: utf-8 -*-
import requests
import threading

class GetRequests:
    def __init__(self):
        self.url = "http://www.baidu.com"
    def requestGetMethod(self):
        r = requests.get(self.url)
        print(r.text)
        print("==========================================================================")

def threadBuild():
    req = GetRequests()
    return req.requestGetMethod()
try:
    i = 0
    threadnums = 10 #线程数
    while i < threadnums:
        re = threading.Thread(target=threadBuild)
        re.start()
        i += 1
except Exception as e:
    print(e)
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/172435
推荐阅读
相关标签
  

闽ICP备14008679号