May 2018
Beginner to intermediate
452 pages
11h 26m
English
Passing a function to a Thread object as target is one way of running code in a thread; a more flexible and powerful approach is to subclass Thread and override its run() method with the code you want to execute. We're going to take this approach with our corporate REST upload function.
First, we'll subclass Thread to a new class called CorporateRestUploader:
class CorporateRestUploader(Thread):
def __init__(self, filepath, upload_url, auth_url,
username, password):
self.filepath = filepath
self.upload_url = upload_url
self.auth_url = auth_url
self.username = username
self.password = password
super().__init__()
The __init__() method takes the same arguments that upload_to_corporate_rest() took and ...