Просмотр исходного кода

【更新】thread 示例程序

SummerGift 6 лет назад
Родитель
Сommit
75b7680abc
1 измененных файлов с 10 добавлено и 6 удалено
  1. 10 6
      examples/basic/_thread_example.py

+ 10 - 6
examples/basic/_thread_example.py

@@ -10,12 +10,16 @@
 
 import _thread
 import utime as time
+import gc
 
 def testThread():
-    while True:
-        print("Hello from thread")
-        time.sleep(2)
+    count = 0
+    while (count < 9):
+        print("Hello rt-thread!")
+        count += 1
 
-_thread.start_new_thread(testThread, ())
-while True:
-    pass
+    print("Thread exit!")
+    gc.collect()    # Free the memory space requested by the thread
+
+# TestThread thread is created with an empty argument
+_thread.start_new_thread(testThread, ())