rpi_envsens/__init__.py

34 lines
771 B
Python
Raw Normal View History

import logging
2020-09-17 19:21:45 +02:00
import threading
import time
2020-09-17 19:21:45 +02:00
DEBUG = False
2020-09-04 12:25:02 +02:00
logger_name = 'RPI_ENVSENS'
logger = logging.getLogger(logger_name)
2020-09-17 19:21:45 +02:00
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()