module:python:checkthread:checkthread
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| module:python:checkthread:checkthread [2021/12/09 20:45] – omdevelop | module:python:checkthread:checkthread [2022/09/13 11:58] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| ===== Benutzung ===== | ===== Benutzung ===== | ||
| - | Beispiel für die Einbindung der MicroPython-Library **Thread.py** : | + | Python-Library **Thread.py** : |
| <code python> | <code python> | ||
| # | # | ||
| - | import | + | import |
| + | import enum as ENU | ||
| + | # | ||
| + | class EStateThread(ENU.Enum): | ||
| + | stIdle = 0 | ||
| + | stBusy = 1 | ||
| + | stEnd = 2 | ||
| + | # | ||
| + | def CBOnExecute(thread): | ||
| + | if (None != thread.OnBusy): | ||
| + | thread.OnBusy(thread) | ||
| + | if (None != thread.OnEnd): | ||
| + | thread.OnEnd(thread) | ||
| # | # | ||
| class CThread(): | class CThread(): | ||
| - | | + | |
| - | def __init__(self, | + | def __init__(self, |
| - | self.ID = threadid | + | self.State = EStateThread.stIdle |
| - | self.OnExecute | + | self.Thread |
| - | self.IsBusy | + | self.OnStart |
| - | | + | |
| - | # | + | |
| - | def Start(self): | + | self.OnEnd = onend |
| - | self.IsBusy | + | |
| - | | + | def Start(self): |
| - | return | + | self.State = EStateThread.stBusy |
| - | # | + | |
| - | def Abort(self): | + | self.OnStart(self) |
| - | self.IsBusy | + | |
| - | | + | |
| - | # | + | # |
| + | def Abort(self): | ||
| + | self.State = EStateThread.stEnd | ||
| + | if (None != self.OnAbort): | ||
| + | | ||
| + | return | ||
| </ | </ | ||
| - | Wichtig: Die Library **Thread.py** muss im FileSystem des MicroControllers vorhanden sein! | ||
| - | Aufrufendes Programm **Esp32CheckThreading.py** : | + | |
| + | Aufrufendes Programm **CheckThread.py** : | ||
| <code python> | <code python> | ||
| # | # | ||
| import time | import time | ||
| # | # | ||
| - | import Thread | + | import Thread |
| # | # | ||
| - | # | + | def CBOnStart(thread): |
| - | def CBOnExecute(thread): | + | print(' |
| - | print(' | + | return |
| - | I = 0 | + | # |
| - | while (thread.IsBusy): | + | def CBOnBusy(thread): |
| - | I += 1 | + | |
| - | | + | while (THR.EStateThread.stBusy == thread.State): |
| - | time.sleep(1) | + | print(' |
| - | print(' | + | time.sleep(1.0) |
| + | | ||
| + | # | ||
| + | def CBOnAbort(thread): | ||
| + | | ||
| + | return | ||
| + | # | ||
| + | def CBOnEnd(thread): | ||
| + | print(' | ||
| + | return | ||
| # | # | ||
| - | # | + | #----------------------------------------------------------- |
| if (' | if (' | ||
| - | | + | |
| - | T = Thread.CThread(' | + | # |
| - | T.Start() | + | |
| - | time.sleep(5) | + | |
| - | T.Abort() | + | time.sleep(5.0) |
| - | | + | |
| - | print(' | + | # |
| + | print(' | ||
| + | # | ||
| # | # | ||
| </ | </ | ||
| Line 65: | Line 93: | ||
| Run-Ausgabe im Terminal: | Run-Ausgabe im Terminal: | ||
| < | < | ||
| - | >>> | + | In [19]: runfile(' |
| - | >>> | + | Reloaded modules: Thread |
| - | >>> | + | *** CheckThread: begin |
| - | CBOnExecute[T1]: | + | CBOnStart |
| - | CBOnExecute[T1]: Hello(1)! | + | CBOnBusy: 0 |
| - | CBOnExecute[T1]: | + | CBOnBusy... |
| - | CBOnExecute[T1]: | + | CBOnBusy... |
| - | CBOnExecute[T1]: | + | CBOnBusy... |
| - | CBOnExecute[T1]: | + | CBOnBusy... |
| - | CBOnExecute[T1]: | + | CBOnBusy... |
| - | *** Esp32CheckThreading: end | + | CBOnAbort |
| - | ♦♦> | + | *** CheckThread: end |
| - | MicroPython v1.17 on 2021-09-02; ESP32 module with ESP32 | + | CBOnEnd |
| - | Type " | + | |
| - | >>> | + | |
| </ | </ | ||
| Line 86: | Line 113: | ||
| ===== Version ===== | ===== Version ===== | ||
| - | {{:module:micropython:2112081352_Esp32CheckThreading_01V01.zip | 2112081352_Esp32CheckThreading_01V01.zip}} | + | {{:module:python:CheckThread: |
module/python/checkthread/checkthread.1639079137.txt.gz · Last modified: 2021/12/09 21:45 (external edit)