This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch v2-5-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit f5fb505eb2f6c4aeeaf3cc71414166057c382642
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Tue Mar 21 20:52:57 2023 +0800

    Fix process killing with subprocess API (#30207)
    
    * Fix process killing with subprocess API
    
    * Improve signal handler typing
    
    (cherry picked from commit d9728eb6703c001a739f9c74e56f549155851f00)
---
 airflow/cli/commands/webserver_command.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/airflow/cli/commands/webserver_command.py 
b/airflow/cli/commands/webserver_command.py
index 685cc42889..14fc17558b 100644
--- a/airflow/cli/commands/webserver_command.py
+++ b/airflow/cli/commands/webserver_command.py
@@ -25,6 +25,7 @@ import subprocess
 import sys
 import textwrap
 import time
+import types
 from contextlib import suppress
 from time import sleep
 from typing import NoReturn
@@ -425,18 +426,22 @@ def webserver(args):
         # then have a copy of the app
         run_args += ["--preload"]
 
-        gunicorn_master_proc: psutil.Process | None = None
+        gunicorn_master_proc: psutil.Process | subprocess.Popen
 
-        def kill_proc(signum, _):
+        def kill_proc(signum: int, frame: types.FrameType | None) -> NoReturn:
             log.info("Received signal: %s. Closing gunicorn.", signum)
             gunicorn_master_proc.terminate()
             with suppress(TimeoutError):
                 gunicorn_master_proc.wait(timeout=30)
-            if gunicorn_master_proc.is_running():
+            if isinstance(gunicorn_master_proc, subprocess.Popen):
+                still_running = gunicorn_master_proc.poll() is not None
+            else:
+                still_running = gunicorn_master_proc.is_running()
+            if still_running:
                 gunicorn_master_proc.kill()
             sys.exit(0)
 
-        def monitor_gunicorn(gunicorn_master_pid: int):
+        def monitor_gunicorn(gunicorn_master_pid: int) -> NoReturn:
             # Register signal handlers
             signal.signal(signal.SIGINT, kill_proc)
             signal.signal(signal.SIGTERM, kill_proc)

Reply via email to