S
S
semolex2016-07-05 17:19:56
Python
semolex, 2016-07-05 17:19:56

How to remake a method in Python using threading?

Hello!
Faced some confusion about how to remake a method of an existing class using threading.
Actually, the task is for the method to load some information in the background using a thread.
Here is an example of what is done:

class MyClass(object): # наследуется именно от object
    """ some stuff"""
    def download(self, url, path):
        do_thread = threading.Thread(target=self.__load, args=(url, path))
        download_thread.daemon = True
        download_thread.start()
    def __load(self, url, name):
        """загрузка файлов с помощью requests"""
        pass

That is, the idea is this - every time the method accepts some URL, it will "send" the download to the thread and, accordingly, will be able to use other methods for itself. And the files will be loaded in the background.
Will this code work? How can you do better?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question