What is the fastest way to send 100,000 HTTP requests in Python?

前端 未结 16 937
暖寄归人
暖寄归人 2020-11-22 07:12

I am opening a file which has 100,000 URL\'s. I need to send an HTTP request to each URL and print the status code. I am using Python 2.6, and so far looked at the many con

16条回答
  •  旧巷少年郎
    2020-11-22 07:25

    For your case, threading will probably do the trick as you'll probably be spending most time waiting for a response. There are helpful modules like Queue in the standard library that might help.

    I did a similar thing with parallel downloading of files before and it was good enough for me, but it wasn't on the scale you are talking about.

    If your task was more CPU-bound, you might want to look at the multiprocessing module, which will allow you to utilize more CPUs/cores/threads (more processes that won't block each other since the locking is per process)

提交回复
热议问题