Send Simultaneous Requests python (all at once)

前端 未结 3 799
别跟我提以往
别跟我提以往 2021-01-04 12:34

I\'m trying to create a script that send\'s over 1000 requests to one page at the same time. But requests library with threading (1000) threads. Seems to be doing to first 5

3条回答
  •  借酒劲吻你
    2021-01-04 13:02

    Assumed that you know what you are doing, I first suggest you to implement a backoff policy with a jitter to prevent "predictable thundering hoardes" to your server. That said, you should consider to do some threading

    import threading
    class FuncThread(threading.Thread):
        def __init__(self, target, *args):
            self._target = target
            self._args = args
            threading.Thread.__init__(self)
    
        def run(self):
            self._target(*self._args)
    

    so that you would do something like

    t = FuncThread(doApiCall, url)
    t.start()
    

    where your method doApiCall is defined like this

    def doApiCall(self, url):
    

提交回复
热议问题