mardi 27 avril 2021

Python Multithreading with a For Loop

I am trying to run the following code with multi threads to increase the speed.

So far everything i have tried just repeats the same iteration for each thread instead of starting the next. Thanks

    for x in array:
        global count
        response = requests.get(x, proxies=proxies, headers=headers)
        content = response.text
        o = content.find(online)
        ago = re.findall("(Show</span>\n[0-9][^.]*?ago)", content)
        ago = ''.join(ago).replace('Show</span>\n', '').replace("months", "MOUNTHS@@@").replace("month", "MOUNTH@@@").replace("weeks", "WEEKS@@@").replace("year", "YEAR@@@").replace("years", "YEARS@@@")
        if content.find(online) != -1:
            count = count + 1
            print(Fore.GREEN + 'Online:', x)
        elif content.find(ofline) != -1:
            print(Fore.RED + x, "-", 'Last Online:',ago)
        else:
            print(Style.RESET_ALL, 'Unknown:', o, x)

Aucun commentaire:

Enregistrer un commentaire