You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Michael-cd30 (via GitHub)" <gi...@apache.org> on 2024/01/31 09:46:02 UTC

Re: [I] Forked processes aren't logged by tasks using the Python Operator [airflow]

Michael-cd30 commented on issue #14813:
URL: https://github.com/apache/airflow/issues/14813#issuecomment-1918745838

   SubprocessHook().run_command() has a limited number of parameters, for exemple "shell" is missing.
   
   You can instead write your own "run" function and send output to logger.getLogger("airflow.task").
   
   I've written this one to meet my needs.
   
   ```
   def check_call(command: str, env: dict = None) -> None:
   
       logger = logging.getLogger("airflow.task")
       logger.info(command)
   
       p = subprocess.Popen(
           command,
           text = True,
           shell = True,
           stdout = subprocess.PIPE,
           stderr = subprocess.PIPE,
           env = env
       )
   
       for line in p.stdout:
           logger.info(line)
   
       exit_code = p.wait()
   
       if exit_code:
           raise subprocess.CalledProcessError(exit_code, command)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org