Thread#
Initializing the Thread Class#
The Thread
constructor creates a Thread object.
This constructor uses two parameters:
Parameter |
Description |
---|---|
|
A previously defined function that will be executed as the entry point when the thread is invoked. |
|
Optional. A tuple that is used to pass arguments to the thread entry function. |
# Define the function "thread_print".
def thread_print():
brain.screen.print("Printing!")
# Construct a Thread "thread" with the
# Thread class.
thread = Thread(thread_print)
This thread
object will be used in all subsequent examples throughout this API documentation when referring to Thread class methods.
Class Methods#
stop()#
The stop()
method stops the thread.
Returns: None.
sleep_for()#
The sleep_for(duration, units)
method makes the thread sleep for a specified duration.
Parameters |
Description |
---|---|
duration |
The duration for which the thread should sleep. |
units |
Optional. A valid TimeUnits type. The default is |
Returns: None.