import logging import threading import time import pipe from io_utils import pop_job_from_pipe is_running = False def start_process_run_job(): try: logging.debug("Running jobs in thread") global thread, is_running thread = threading.Thread(target=run_job) thread.daemon = True is_running = True pipe.init() thread.start() except Exception as e: print("Failed to start thread: ", e) def stop_thread(): logging.debug("Stop thread") global is_running is_running = False def run_job(): global is_running while is_running: try: pop_job_from_pipe() time.sleep(10) except KeyboardInterrupt: logging.debug("KeyboardInterrupt stop background thread") is_running = False break