Python Forum
How can i add multithreading in this example
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i add multithreading in this example
#1
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()
Reply
#2
https://docs.python.org/3/library/threading.html
Reply
#3
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.
Reply
#4
Lots of nice videos on YouTube. Some even use your example because it is I/O bound.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  multithreading Hanyx 4 1,283 Jul-29-2022, 07:28 AM
Last Post: Larz60+
Question Problems with variables in multithreading Wombaz 2 1,286 Mar-08-2022, 03:32 PM
Last Post: Wombaz
  Multithreading question amadeok 0 1,748 Oct-17-2020, 12:54 PM
Last Post: amadeok
  matplotlib multithreading catosp 0 2,909 Jul-03-2020, 09:33 AM
Last Post: catosp
  Multithreading dynamically syncronism Rodrigo 0 1,504 Nov-08-2019, 02:33 AM
Last Post: Rodrigo
  Locks in Multithreading Chuonon 0 1,822 Oct-03-2019, 04:16 PM
Last Post: Chuonon
  multithreading issue with output mr_byte31 4 3,149 Sep-11-2019, 12:04 PM
Last Post: stullis
  Multithreading alternative MartinV279 1 2,732 Aug-01-2019, 11:41 PM
Last Post: scidam
  using locks in multithreading in python3 srm 2 3,617 Jul-13-2019, 11:35 AM
Last Post: noisefloor
  Multithreading in a loop valtih 3 16,344 Aug-03-2017, 08:20 PM
Last Post: valtih

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020