34 рядки
771 B
Python
34 рядки
771 B
Python
import logging
|
|
import threading
|
|
import time
|
|
|
|
DEBUG = False
|
|
|
|
logger_name = 'RPI_ENVSENS'
|
|
logger = logging.getLogger(logger_name)
|
|
|
|
|
|
class background_task(object):
|
|
RUN_SLEEP_TIME = 2.0
|
|
|
|
def __init__(self):
|
|
self.__active__ = True
|
|
self.__thread__ = threading.Thread(target=self.run, args=())
|
|
self.__thread__.daemon = True # Daemonize thread
|
|
self.__thread__.start() # Start the execution
|
|
|
|
def __run__(self):
|
|
pass
|
|
|
|
def run(self):
|
|
while self.__active__:
|
|
self.__run__()
|
|
time.sleep(self.RUN_SLEEP_TIME)
|
|
|
|
def close(self):
|
|
self.__active__ = False
|
|
self.__thread__.join()
|
|
|
|
def __del__(self):
|
|
self.close()
|