module:micropython:esp32checkthreading
Table of Contents
MicroPython: Esp32CheckThreading
Benutzung
Beispiel für die Einbindung der MicroPython-Library Thread.py :
# import _thread # class CThread(): # def __init__(self, threadid, onexecute): self.ID = threadid self.OnExecute = onexecute self.IsBusy = False return # def Start(self): self.IsBusy = True _thread.start_new_thread(self.OnExecute, [self]) return # def Abort(self): self.IsBusy = False return #
Wichtig: Die Library Thread.py muss im FileSystem des MicroControllers vorhanden sein!
Aufrufendes Programm Esp32CheckThreading.py :
# import time # import Thread # #----------------------------------------- def CBOnExecute(thread): print('CBOnExecute[{}]: begin'.format(thread.ID)) I = 0 while (thread.IsBusy): I += 1 print("CBOnExecute[{}]: Hello({})!".format(thread.ID, I)) time.sleep(1) print('CBOnExecute[{}]: end'.format(thread.ID)) # #----------------------------------------- if ('__main__' == __name__): print('*** Esp32CheckThreading: begin') T = Thread.CThread('T1', CBOnExecute) T.Start() time.sleep(5) T.Abort() time.sleep(5) print('*** Esp32CheckThreading: end') #
Run-Ausgabe im Terminal:
>>> Running ..\Esp32Threading.py >>> >>> *** Esp32CheckThreading: begin CBOnExecute[T1]: begin CBOnExecute[T1]: Hello(1)! CBOnExecute[T1]: Hello(2)! CBOnExecute[T1]: Hello(3)! CBOnExecute[T1]: Hello(4)! CBOnExecute[T1]: Hello(5)! CBOnExecute[T1]: end *** Esp32CheckThreading: end ♦♦> MicroPython v1.17 on 2021-09-02; ESP32 module with ESP32 Type "help()" for more information. >>>
Version
module/micropython/esp32checkthreading.txt · Last modified: 2022/09/13 11:58 by 127.0.0.1