How to define a thread
The simplest way to use a thread is to instantiate it with a target function and then call the start()
method to let it begin its work. The Python module threading has the Thread()
method that is used to run processes and functions in a different thread:
class threading.Thread(group=None, target=None, name=None, args=(), kwargs={})
In the preceding code:
group
: This is the value ofgroup
that should beNone
; this is reserved for future implementationstarget
: This is the function that is to be executed when you start a thread activityname
: This is the name of the thread; by default, a unique name of the formThread-N
is assigned to itargs
: This is the tuple of arguments that are to be passed to a targetkwargs
: This is the dictionary of keyword arguments that are to be used for the target function
It is useful to spawn a thread and pass arguments to it that tell it what work...