environment sensor library for raspberry dependencies to adafruit exist
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

12345678910111213141516171819202122232425262728293031323334353637
  1. import logging
  2. import threading
  3. import time
  4. DEBUG = False
  5. try:
  6. from config import APP_NAME as ROOT_LOGGER_NAME
  7. except ImportError:
  8. ROOT_LOGGER_NAME = 'root'
  9. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  10. class background_task(object):
  11. RUN_SLEEP_TIME = 2.0
  12. def __init__(self):
  13. self.__active__ = True
  14. self.__thread__ = threading.Thread(target=self.run, args=())
  15. self.__thread__.daemon = True # Daemonize thread
  16. self.__thread__.start() # Start the execution
  17. def __run__(self):
  18. pass
  19. def run(self):
  20. while self.__active__:
  21. self.__run__()
  22. time.sleep(self.RUN_SLEEP_TIME)
  23. def close(self):
  24. self.__active__ = False
  25. self.__thread__.join()
  26. def __del__(self):
  27. self.close()