def _handle_proc_interrupt(proc): log.info("Operation interrupted - waiting for process to exit") kill_after = time.time() + PROC_TERM_TIMEOUT_SECONDS while time.time() < kill_after: if proc.poll() is not None: break time.sleep(1) if proc.poll() is None: log.warning("Operation process did not exit - stopping forcefully") util.kill_process_tree(proc.pid, force=True) return exit_code.SIGTERM
def _handle_proc_keyboard_interrupt(proc): log_waiting_after = time.time() + LOG_WAITING_DELAY_SECONDS kill_after = time.time() + PROC_TERM_TIMEOUT_SECONDS while time.time() < kill_after: if log_waiting_after and time.time() > log_waiting_after: if os.getenv("NO_OP_INTERRUPTED_MSG") != "1": log.info("Operation interrupted - waiting for process to exit") log_waiting_after = None if proc.poll() is not None: break time.sleep(1) if proc.poll() is None: log.warning("Operation process did not exit - stopping forcefully") util.kill_process_tree(proc.pid, force=True) return exit_code.KEYBOARD_INTERRUPT