How can i add multithreading in this example - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How can i add multithreading in this example (/thread-28938.html) |
How can i add multithreading in this example - WoodyWoodpecker1 - Aug-10-2020 How can i add multithreading in this example import xml.etree.ElementTree as et import requests from bs4 import BeautifulSoup import threading iterar = input ('How many domains you want to check: ') domainlist = [] try: iterar = int(iterar) except ValueError: print('incorrect value') if iterar <= 0: print('Please write a count of domains you want to be cheked') i=0 while i<iterar: i=i+1 domainCounter = input(f'Enter Domain N{i}:') domainlist.append(domainCounter) while domainlist: domain = domainlist.pop(0) result = requests.get(f'http://data.alexa.com/data?cli=20&dat=snbamz&url={domain}', stream = True) data_string = result.text root = et.fromstring(data_string) rank = [item.attrib.get('RANK') for item in root.findall('.//REACH')] print(f"\nDomain: \'{domain}\'") print(f"Alexa Rank: {rank}\n".replace("[", "").replace("]", '')) input() RE: How can i add multithreading in this example - Axel_Erfurt - Aug-11-2020 https://docs.python.org/3/library/threading.html RE: How can i add multithreading in this example - Narendra8989 - Aug-11-2020 Creating Thread Using Threading Module in Python. Define a new subclass of the Thread class. Override the __init__(self [,args]) method to add additional arguments. Then, override the run(self [,args]) method to implement what the thread should do when started. RE: How can i add multithreading in this example - deanhystad - Aug-11-2020 Lots of nice videos on YouTube. Some even use your example because it is I/O bound. |