Python Forum
How to make each thread send multiple requests in python3?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make each thread send multiple requests in python3?
#1
I have written this script below and wanted to see how I can edit the script so that each thread sends multiple requests? Any suggestions how I can achieve this?

def get_data(host, url, req_id): conn = http.client.HTTPSConnection(host,timeout=10, context=ssl._create_unverified_context()) headers = { "Accept":"application/json", } start = time.process_time() print("Sending Req: {}".format(req_id)) conn.request("GET", url, headers=headers) response = conn.getresponse() request_time = time.process_time() - start print("Req: {} Status: {}{} ResponseTime: {}".format(req_id, response.status, response.reason, request_time)) if __name__ == "__main__": url = "/maps" host = "google.com" nr_threads = 10 if len(sys.argv) == 2: nr_threads = int(sys.argv[1]) try: threads = [] for i in range(nr_threads): t = Thread(target=get_data, args=(host, url,i)) t.start() threads.append(t) for t in threads: t.join() except Exception as e: print("Exception: ", e)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to handle multiple audio uploads without canceling ongoing API requests? muba 2 2,492 Jan-01-2025, 01:04 AM
Last Post: Skaperen
  Python3 List in requests ogautier 1 2,087 Mar-04-2022, 12:09 PM
Last Post: DeaD_EyE
  Python3 requests.models.Response ogautier 4 10,444 Feb-17-2022, 04:46 PM
Last Post: ogautier
  How to make scraper send email notification just once themech25 0 2,304 Nov-08-2021, 01:51 PM
Last Post: themech25
  convert string into multiple columns in python3 VAN 2 3,979 Sep-26-2020, 11:14 PM
Last Post: scidam
  Error SQLite objects created in a thread can only be used in that same thread. binhduonggttn 3 21,732 Jan-31-2020, 11:08 AM
Last Post: DeaD_EyE
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 7,091 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  Using a file to send multiple contacts Text via GSM sim 01001B 0 3,140 Sep-14-2019, 05:41 PM
Last Post: 01001B
  how this to make a asyncio thread safe? linziyan 0 4,071 Jun-07-2018, 10:33 AM
Last Post: linziyan
  Is this a normal/benign make test error when building python3.6 sofuego 2 5,018 Feb-12-2018, 12:32 AM
Last Post: sofuego

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.