Parameterizing the target method

When using the constructor of the Thread class, it's possible to specify the arguments of the target method via the args parameter:

    def start_action(self):
self.button.config(state=tk.DISABLED)
thread = threading.Thread(target=self.run_action, args=(5,))
thread.start()
self.check_thread(thread)

def run_action(self, timeout):
# ...

Note that the self parameter is passed automatically since we are using the current instance to reference the target method. This might be handy in scenarios where the new thread needs to access information from the caller instance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset