Apr-29-2020, 02:42 PM
(This post was last modified: Apr-29-2020, 02:43 PM by Contra_Boy.)
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)