User Tools

Site Tools


module:micropython:esp32checkthreading

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
module:micropython:esp32checkthreading [2021/12/08 13:45] – [Benutzung] omdevelopmodule:micropython:esp32checkthreading [2022/09/13 11:58] (current) – external edit 127.0.0.1
Line 16: Line 16:
  
 ===== Benutzung ===== ===== Benutzung =====
-Beispiel für die Einbindung der MicroPython-Library **Threading.py** :+Beispiel für die Einbindung der MicroPython-Library **Thread.py** :
 <code python> <code python>
 +#
 +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
 +  #
 </code> </code>
-Wichtig: Die Library muss im FileSystem des MicroControllers vorhanden sein!+Wichtig: Die Library **Thread.py** muss im FileSystem des MicroControllers vorhanden sein!
  
 Aufrufendes Programm **Esp32CheckThreading.py** : Aufrufendes Programm **Esp32CheckThreading.py** :
 <code python> <code python>
 +
 +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'
 +#
 </code> </code>
  
Line 48: Line 92:
 ===== Version ===== ===== Version =====
  
-{{:module:micropython:2112 _esp32checkthreading_01v.zip | 2112_Esp32CheckThreading   .zip}} +{{:module:micropython:2112081352_Esp32CheckThreading_01V01.zip | 2112081352_Esp32CheckThreading_01V01.zip}}
- +
-===== ===== +
- +
- +
- +
- +
  
 ----- -----
module/micropython/esp32checkthreading.1638967533.txt.gz · Last modified: 2021/12/08 14:45 (external edit)