1

I want to call this function with different threads each containing different values from the loop. The result and how I want it is shown below. As is my script.

Result with (3) Threads

Checking Data x
Checking Data x
Checking Data x
Checking Data y
Checking Data y
Checking Data y
Checking Data z
Checking Data z
Checking Data z

What i want with (3) Threads

Checking Data x
Checking Data y
Checking Data z

My script:

from threading import Thread #Imports


def checker(urls):
    print(f"Checking Data {urls}")

threads = []
urls = open("links.txt", "r").readlines() # loading And reading textfile lines
urls = (linez.replace("\n", "")for linez in urls) 
for linez in urls: # First Loop
    # Data Below is to be sent to threads
    data = linez
    #Data Above is to be sent to threads
    for i in range(3): #Second Loop Inside First Loop
        process = Thread(target=checker, args=[data])
        process.start()
        threads.append(process)

for x in threads: #Third Alone xD Loop
    x.join()
Community
  • 1
  • 1
  • why do u need it? "for i in range(3):" – Dmitrii Mar 16 '19 at 15:20
  • Well i am new to threading and i thought that's how you create threads lol.. i want to post urls which i have loaded from the txt file with threads each carrying different url and calling the function ... :v but i have been failing – Habab Ali Khan Mar 16 '19 at 15:32
  • Try other approach, https://stackoverflow.com/questions/55186122/asyncio-aiohttp-not-returning-response/55186376#55186376 – Dmitrii Mar 16 '19 at 15:49

0 Answers0