线#

初始化线程类#

使用以下构造函数创建线程:

线程(回调,参数)

此构造函数使用两个参数:

范围

描述

回调

先前定义的函数,将在线程调用时作为入口点执行。

arg

**可选。**用于向线程入口函数传递参数的元组。

# Define the function "thread_print".
def thread_print():
    brain.screen.print("Printing!")
# Construct a Thread "thread" with the
# Thread class.
thread = Thread(thread_print)

当引用 Thread 类方法时,此“thread”对象将在整个 API 文档的所有后续示例中使用。

类方法#

stop()#

stop() 方法停止线程。

**返回:**无。

sleep_for()#

sleep_for(duration, units) 方法使线程休眠指定的时间。

参数

描述

期间

线程应休眠的持续时间。

单位

**可选。**有效的 TimeUnits 类型。默认值为 MSEC

**返回:**无。