import utime as time
import _thread
def th():
for i in range (5):
print('--- new_thread ---')
time.sleep_ms(1000)
#循环结束
print('_thread.exit')
_thread.exit()
if __name__ == '__main__':
_thread.start_new_thread(th, ()) #开启gps线程
while True:
print('=== main ===')
time.sleep_ms(1000)

| get_ident | stack_size | start_new_thread | exit | allocate_lock |
|---|---|---|---|---|
| 获取当前线程ID | 设置创建新线程时所使用的栈大小 | 创建一个新线程 | 结束线程 | 创建一个互斥锁对象 |
函数原型:
返回值:
函数原型:
参数说明:
| 参数 | 类型 | 必选参数? | 说明 |
|---|---|---|---|
| size | int | 是 | 创建新线程使用的栈大小(以字节为单位),默认为8448字节,最小8192字节。 |
函数原型:
参数说明:
| 参数 | 类型 | 必选参数? | 说明 |
|---|---|---|---|
| function | 函数指针 | 是 | 新线程的入口函数 |
| args | 元组 | 是 | 传入新线程的入口函数的参数列表 |
返回值:
函数原型:
函数原型:
返回值: