0

I want it to send ~25 requests per second. Please help.

import requests
x = 1

for i in range(100):
    requests.get("...")
    print(x)
    x += 1
8
  • 3
    Maybe have a look at async or multiprocessing# Commented Dec 19, 2021 at 19:20
  • 3
    Are you trying to stage a ddos attack or something? Commented Dec 19, 2021 at 19:24
  • no im not a bad person Commented Dec 19, 2021 at 19:26
  • well you could start multiple subprocess treads or use more programm istances together Commented Dec 19, 2021 at 19:32
  • im beginner, that multiple subprocess treads doesnt say anything to me Commented Dec 19, 2021 at 19:37

1 Answer 1

2

You can use treads to run multiple requests at the same time. Look at this tutorial for more information about threading in python.

In your case, you can use something like this:

from threading import Thread

# target function
def foo():
    for i in range(4): 
        requests.get("...")

# create 25 new threads
threadList = []
for t in range(25):
    newThread = Thread(target=foo)
    threadList.append(newThread)

# start all threads
for t in threadList:
    t.start()

for t in threadList:
    t.join()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.