0

I wanted to download files from the web and name them, plus i wanted to make a thread so i will download different files at the same time.

import urllib.request
import threading


class mythread(threading.Thread):
    def __init__(self, threadID, Name, URL):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.Name = Name
        self.URL = URL

    def run(self):
        print("Starting :" + self.Name + " \n ")
        download_data(self.URL, 1, self.Name)
        print("Exiting :" + self.Name + " \n ")


def download_data(URL, delay, Name):
    URL = " "
    response = urllib.request.urlopen(URL)

    data = response.read()
    text = data.decode('utf-8')
    while text:
        time.sleep(delay)
        if text is None:
            break
        print(text)     

thread1 = mythread(1, romeo, https: // www.py4e.com/code3/romeo-full.txt) 
thread2 = mythread(2, romeo2, https: // www.py4e.com/code3/romeo.txt)


thread1.start()
thread2.start()
thread1.join()
thread2.join()

it does not need to print i just did that for debugging purposes.

this are some example sites

Dagi
  • 1
  • 2

1 Answers1

0

Why are you overwriting the URL parameter ? Have you tried removing this line ?

You may benefit from having more logging, and What is a debugger and how can it help me diagnose problems?

Lenormju
  • 4,078
  • 2
  • 8
  • 22