diff --git a/airflow/jobs/local_task_job.py b/airflow/jobs/local_task_job.py index 4b291535b99ca..203a7a82b20b3 100644 --- a/airflow/jobs/local_task_job.py +++ b/airflow/jobs/local_task_job.py @@ -192,14 +192,17 @@ def heartbeat_callback(self, session=None): ) raise AirflowException("Hostname of job runner does not match") current_pid = self.task_runner.process.pid - - same_process = ti.pid == current_pid + recorded_pid = ti.pid + same_process = recorded_pid == current_pid if ti.run_as_user or self.task_runner.run_as_user: - same_process = psutil.Process(ti.pid).ppid() == current_pid + recorded_pid = psutil.Process(ti.pid).ppid() + same_process = recorded_pid == current_pid - if ti.pid is not None and not same_process: - self.log.warning("Recorded pid %s does not match " "the current pid %s", ti.pid, current_pid) + if recorded_pid is not None and not same_process: + self.log.warning( + "Recorded pid %s does not match the current pid %s", recorded_pid, current_pid + ) raise AirflowException("PID of job runner does not match") elif self.task_runner.return_code() is None and hasattr(self.task_runner, 'process'): self.log.warning(