in images/airflow/2.9.2/python/mwaa/subprocess/subprocess.py [0:0]
def _shutdown_python_subprocess(self, process: Popen[Any]):
# Do nothing if process has already terminated
if self.process is None or self.process.poll() is not None:
return
module_logger.info(f"Shutting down {self}")
try:
module_logger.info(f"Sending SIGTERM to {self}")
self.process.terminate()
action_taken = "terminated"
except OSError:
module_logger.error(f"Failed to send SIGTERM to {self}. Sending SIGKILL...")
self.process.kill()
action_taken = "killed"
sigterm_patience_interval_secs = self.sigterm_patience_interval.total_seconds()
try:
outs, _ = self.process.communicate(timeout=sigterm_patience_interval_secs)
if outs:
self.process_logger.info(outs.decode("utf-8"))
except subprocess.TimeoutExpired:
module_logger.error(
f"Failed to kill {self} with a SIGTERM signal. Process didn't "
f"respond to SIGTERM after {sigterm_patience_interval_secs} "
"seconds. Sending SIGKILL..."
)
self.process.kill()
action_taken = "killed"
module_logger.info(
f"Process {action_taken}. Return code is {self.process.returncode}."
)