import time import logging from paramiko.ssh_exception import SSHException from report_ops.status import QuantifiRemote logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def close_and_reconnect(): retries = 5 for i in range(retries): try: QuantifiRemote._client.client.close() QuantifiRemote.init_client() except (SSHException, OSError) as e: if i == retries - 1: raise e else: time.sleep(60 * i) else: return def run(): while True: try: for f in QuantifiRemote._client.list_files("/OUTGOING/Status"): QuantifiRemote.process(f) except (SSHException, OSError) as e: logger.info(e) close_and_reconnect() time.sleep(60) QuantifiRemote.check_cache() if __name__ == "__main__": run()