From 4ba513cf67d187d73dec31115bd8fd2f40b9b403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <6774676+eumiro@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:41:30 +0200 Subject: [PATCH] Refactor unneeded 'continue' jumps in cli --- airflow/cli/cli_config.py | 8 ++------ airflow/cli/commands/internal_api_command.py | 5 ++--- airflow/cli/commands/kubernetes_command.py | 4 ++-- airflow/cli/commands/webserver_command.py | 5 ++--- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/airflow/cli/cli_config.py b/airflow/cli/cli_config.py index e8e096ee6fa71..01dbe7080c6ce 100644 --- a/airflow/cli/cli_config.py +++ b/airflow/cli/cli_config.py @@ -92,12 +92,8 @@ def __init__( self.flags = flags self.kwargs = {} for k, v in locals().items(): - if v is _UNSET: - continue - if k in ("self", "flags"): - continue - - self.kwargs[k] = v + if k not in ("self", "flags") and v is not _UNSET: + self.kwargs[k] = v def add_to_parser(self, parser: argparse.ArgumentParser): """Add this argument to an ArgumentParser.""" diff --git a/airflow/cli/commands/internal_api_command.py b/airflow/cli/commands/internal_api_command.py index b9b77c093446d..7b2cf798da8dc 100644 --- a/airflow/cli/commands/internal_api_command.py +++ b/airflow/cli/commands/internal_api_command.py @@ -187,11 +187,10 @@ def monitor_gunicorn(gunicorn_master_pid: int): # Reading pid of gunicorn main process as it will be different that # the one of process spawned above. - while True: + gunicorn_master_proc_pid = None + while not gunicorn_master_proc_pid: sleep(0.1) gunicorn_master_proc_pid = read_pid_from_pidfile(pid_file) - if gunicorn_master_proc_pid: - break # Run Gunicorn monitor gunicorn_master_proc = psutil.Process(gunicorn_master_proc_pid) diff --git a/airflow/cli/commands/kubernetes_command.py b/airflow/cli/commands/kubernetes_command.py index 038f53e3f3707..2d9a488ebbc5e 100644 --- a/airflow/cli/commands/kubernetes_command.py +++ b/airflow/cli/commands/kubernetes_command.py @@ -142,8 +142,8 @@ def cleanup_pods(args): _delete_pod(pod.metadata.name, namespace) except ApiException as e: print(f"Can't remove POD: {e}", file=sys.stderr) - continue - print(f"No action taken on pod {pod_name}") + else: + print(f"No action taken on pod {pod_name}") continue_token = pod_list.metadata._continue if not continue_token: break diff --git a/airflow/cli/commands/webserver_command.py b/airflow/cli/commands/webserver_command.py index d0b246eed0365..79694db59da91 100644 --- a/airflow/cli/commands/webserver_command.py +++ b/airflow/cli/commands/webserver_command.py @@ -493,11 +493,10 @@ def monitor_gunicorn(gunicorn_master_pid: int) -> NoReturn: # Reading pid of gunicorn master as it will be different that # the one of process spawned above. - while True: + gunicorn_master_proc_pid = None + while not gunicorn_master_proc_pid: sleep(0.1) gunicorn_master_proc_pid = read_pid_from_pidfile(pid_file) - if gunicorn_master_proc_pid: - break # Run Gunicorn monitor gunicorn_master_proc = psutil.Process(gunicorn_master_proc_pid)