Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqian90 committed May 28, 2021
1 parent e86e079 commit 7caba4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
31 changes: 18 additions & 13 deletions airflow/jobs/scheduler_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,24 +754,29 @@ def register_signals(self) -> None:

def _exit_gracefully(self, signum, frame) -> None: # pylint: disable=unused-argument
"""Helper method to clean up processor_agent to avoid leaving orphan processes."""
if _is_parent_process():
if not _is_parent_process():
# Only the parent process should perform the cleanup.
self.log.info("Exiting gracefully upon receiving signal %s", signum)
if self.processor_agent:
self.processor_agent.end()
sys.exit(os.EX_OK)
return

self.log.info("Exiting gracefully upon receiving signal %s", signum)
if self.processor_agent:
self.processor_agent.end()
sys.exit(os.EX_OK)

def _debug_dump(self, signum, frame): # pylint: disable=unused-argument
if _is_parent_process():
try:
sig_name = signal.Signals(signum).name # pylint: disable=no-member
except Exception: # pylint: disable=broad-except
sig_name = str(signum)
if not _is_parent_process():
# Only the parent process should perform the debug dump.
return

try:
sig_name = signal.Signals(signum).name # pylint: disable=no-member
except Exception: # pylint: disable=broad-except
sig_name = str(signum)

self.log.info("%s\n%s received, printing debug\n%s", "-" * 80, sig_name, "-" * 80)
self.log.info("%s\n%s received, printing debug\n%s", "-" * 80, sig_name, "-" * 80)

self.executor.debug_dump()
self.log.info("-" * 80)
self.executor.debug_dump()
self.log.info("-" * 80)

def is_alive(self, grace_multiplier: Optional[float] = None) -> bool:
"""
Expand Down
3 changes: 0 additions & 3 deletions tests/executors/test_celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,6 @@ def register_signals():
Register the same signals as scheduler does to test celery_executor to make sure it does not
hang.
"""

print(f"{os.getpid()} register_signals()")

orig_sigint = orig_sigterm = orig_sigusr2 = signal.SIG_DFL

orig_sigint = signal.signal(signal.SIGINT, _exit_gracefully)
Expand Down

0 comments on commit 7caba4f

Please sign in to comment.