You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.0 KiB
54 lines
2.0 KiB
6 years ago
|
from threading import Timer
|
||
|
import datetime
|
||
|
import subprocess
|
||
|
import importlib
|
||
6 years ago
|
import logging
|
||
5 years ago
|
import Processor
|
||
5 years ago
|
|
||
|
global mGlobalDict
|
||
|
|
||
6 years ago
|
class RepeatedTimer(object):
|
||
|
def __init__(self, interval, function, *args, **kwargs):
|
||
|
self._timer = None
|
||
|
self.interval = interval
|
||
|
self.function = function
|
||
|
self.args = args
|
||
|
self.kwargs = kwargs
|
||
|
self.is_running = False
|
||
|
self.start()
|
||
|
def _run(self):
|
||
|
self.is_running = False
|
||
|
lResult = self.function(*self.args, **self.kwargs)
|
||
|
if lResult is not None:
|
||
|
if lResult:
|
||
|
self.start()
|
||
|
def start(self):
|
||
|
if not self.is_running:
|
||
|
self._timer = Timer(self.interval, self._run)
|
||
|
self._timer.start()
|
||
|
self.is_running = True
|
||
|
|
||
|
def stop(self):
|
||
|
self._timer.cancel()
|
||
|
self.is_running = False
|
||
|
|
||
|
############################################################
|
||
|
####Техническая функция обработки таймера - потока
|
||
|
############################################################
|
||
5 years ago
|
def activityLoopExecution(inLoopTimeEndDateTime, inActivity):
|
||
6 years ago
|
lResultGoLoop=True
|
||
|
lCurrentDateTime=datetime.datetime.now()
|
||
5 years ago
|
#Запустить актитвость через процессор (orchestratorProcessor)
|
||
5 years ago
|
Processor.ActivityListOrDict(inActivity)
|
||
6 years ago
|
#Выключить таймер, если время наступило
|
||
|
if lCurrentDateTime>=inLoopTimeEndDateTime:
|
||
|
lResultGoLoop=False
|
||
|
#Вернуть результат
|
||
|
return lResultGoLoop
|
||
|
############################################################
|
||
|
####Функция запуска таймера - потока
|
||
|
############################################################
|
||
5 years ago
|
def activityLoopStart(inActivityLoopSeconds, inLoopTimeEndDateTime, inActivity):
|
||
|
lTimer = RepeatedTimer(inActivityLoopSeconds, activityLoopExecution, inLoopTimeEndDateTime, inActivity) # it auto-starts, no need of rt.start()
|
||
6 years ago
|
lTimer.start()
|