User Tools

Site Tools


module:python:checkthread:checkthread

Differences

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

Link to this comparison view

Next revision
Previous revision
module:python:checkthread:checkthread [2021/12/09 20:43] – created omdevelopmodule:python:checkthread:checkthread [2022/09/13 11:58] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== CheckThread ====== ====== CheckThread ======
 +[[http://www.openhardsoftware.de/ | Open Hard- & Software]]
 +[
 +[[http://www.openhardsoftware.de/dokuwiki | DokuWiki]]
 +[[http://www.openhardsoftware.de/websites | WebSites]]
 +[[http://www.openhardsoftware.de/mediawiki | MediaWiki]]
 +[[http://www.openhardsoftware.de/nextcloud | NextCloud]]
 +]
 +
 +===== Benutzung =====
 +Python-Library **Thread.py** :
 +<code python>
 +#
 +import threading as THR
 +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():
 +    #
 +    def __init__(self, onstart, onbusy, onabort, onend):
 +        self.State = EStateThread.stIdle
 +        self.Thread = THR.Thread(target=CBOnExecute, args=(self,))
 +        self.OnStart = onstart
 +        self.OnBusy = onbusy
 +        self.OnAbort = onabort
 +        self.OnEnd = onend
 +    #
 +    def Start(self):
 +        self.State = EStateThread.stBusy
 +        if (None != self.OnStart):
 +            self.OnStart(self)
 +        self.Thread.start()
 +        return   
 +    #
 +    def Abort(self):
 +        self.State = EStateThread.stEnd
 +        if (None != self.OnAbort):
 +            self.OnAbort(self)
 +        return
 +</code>
 +
 +
 +Aufrufendes Programm **CheckThread.py** :
 +<code python>
 +#
 +import time
 +#
 +import Thread as THR
 +#
 +def CBOnStart(thread):
 +    print('CBOnStart')
 +    return
 +#
 +def CBOnBusy(thread):
 +    print('CBOnBusy: 0')
 +    while (THR.EStateThread.stBusy == thread.State):
 +        print('CBOnBusy...')
 +        time.sleep(1.0)
 +    return
 +#
 +def CBOnAbort(thread):
 +    print('CBOnAbort')
 +    return
 +#
 +def CBOnEnd(thread):
 +    print('CBOnEnd')
 +    return
 +#
 +#-----------------------------------------------------------
 +if ('__main__' == __name__):
 +    print('*** CheckThread: begin')
 +    #
 +    Thread = THR.CThread(CBOnStart, CBOnBusy, CBOnAbort, CBOnEnd)
 +    Thread.Start()
 +    time.sleep(5.0)
 +    Thread.Abort()
 +    #
 +    print('*** CheckThread: end')
 +    #
 +#
 +</code>
 +
 +Run-Ausgabe im Terminal:
 +<code>
 +In [19]: runfile('C:/Downloads/python/CheckThread.py', wdir='C:/Downloads/python')
 +Reloaded modules: Thread
 +*** CheckThread: begin
 +CBOnStart
 +CBOnBusy: 0
 +CBOnBusy...
 +CBOnBusy...
 +CBOnBusy...
 +CBOnBusy...
 +CBOnBusy...
 +CBOnAbort
 +*** CheckThread: end
 +CBOnEnd
 +
 +</code>
 +
 +
 +
 +===== Version =====
 +
 +{{:module:python:CheckThread:2112092053_CheckThread_01V01.zip | 2112092053_CheckThread_01V01.zip}}
 +
 +
 +------
 +[[http://www.openhardsoftware.de/ | Open Hard- & Software]]
 +[
 +[[http://www.openhardsoftware.de/dokuwiki | DokuWiki]]
 +[[http://www.openhardsoftware.de/websites | WebSites]]
 +[[http://www.openhardsoftware.de/mediawiki | MediaWiki]]
 +[[http://www.openhardsoftware.de/nextcloud | NextCloud]]
 +]
 +
 +
module/python/checkthread/checkthread.1639079021.txt.gz · Last modified: 2021/12/09 21:43 (external edit)