def _shutdown_on_exception(app: skein.ApplicationClient): # Ensure SIGINT is not masked to enable kill on C-c. import signal signal.signal(signal.SIGINT, signal.default_int_handler) try: yield except (KeyboardInterrupt, SystemExit): with suppress(SkeinError): app.shutdown(FinalStatus.KILLED) logger.error("Application killed on user request") except Exception: with suppress(SkeinError): app.shutdown(FinalStatus.FAILED) logger.exception("Application shutdown due to an exception") raise
def _shutdown_on_exception(app: skein.ApplicationClient, path_to_log_hdfs: str = None): # Ensure SIGINT is not masked to enable kill on C-c. import signal signal.signal(signal.SIGINT, signal.default_int_handler) try: yield except (KeyboardInterrupt, SystemExit): with suppress(SkeinError): app.shutdown(FinalStatus.KILLED) logger.error("Application killed on user request") except Exception: with suppress(SkeinError): app.shutdown(FinalStatus.FAILED) logger.exception("Application shutdown due to an exception") raise finally: if path_to_log_hdfs: with tf.gfile.GFile(f'{path_to_log_hdfs}/yarn_logs.txt', 'wb') as fd: fd.write(app_logs(app))