Instructions
Thank you for your interest in our job opening. As a next step, we are expecting you to complete a short assignment.
You need to write a script using Python and share the code or link to directly execute the code.
Task
You are given a list of URLs that point to image files on the web. Your task is to download these image files concurrently using multithreading in Python. You should use object-oriented programming concepts to organize your code into classes and objects.
Here are the requirements for your solution:
- Create a
DownloadManagerclass that manages the download of the image files. TheDownloadManagershould take in a list of URLs to download when it is instantiated. - Create a
DownloadThreadclass that extends theThreadclass from thethreadingmodule. TheDownloadThreadshould take in a URL to download when it is instantiated. TheDownloadThreadshould download the image file from the URL and save it to disk. - Use the
DownloadThreadclass to download the image files concurrently. Use a fixed number of threads to download the image files concurrently. You can specify the number of threads to use when you instantiate theDownloadManager. - Once all the image files are downloaded, print a message indicating that the download is complete.
Here’s an example of how the DownloadManager class should be used along with the urls:
urls = [ “https://free-thesis.com/wp-content/uploads/2022/02/Depression-Detection-Framework-EEG-free-thesis.png”, “https://free-thesis.com/wp-content/uploads/2018/04/output-of-PSO-tuned-MPPT-control.png”, “https://free-thesis.com/wp-content/uploads/2018/04/PSO-Tuned-MPPT-Control-of-PV-array.png”, “https://free-thesis.com/wp-content/uploads/2018/04/2-1.png”, “https://free-thesis.com/wp-content/uploads/2018/04/motor_5.png”, “https://free-thesis.com/wp-content/uploads/2018/04/motor_2.png”, ] dm = DownloadManager(urls, num_threads=5) dm.start_download()
Kindly Submit the solution through this form.
