You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/05/09 02:44:24 UTC

[GitHub] [airflow] xinbinhuang opened a new pull request #15743: Redirect forked process output to logger

xinbinhuang opened a new pull request #15743:
URL: https://github.com/apache/airflow/pull/15743


   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


-- 
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.

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



[GitHub] [airflow] ashb commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
ashb commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-838521255


   Okay, yes I can reproduce it. Got it, sorry.
   
   I didn't read properly and was testing with bash, not realizing this was particular to python operator only.
   
   @andrewgodwin @uranusjr Any better ideas, or does this seem like an okay approach?


-- 
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.

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



[GitHub] [airflow] xinbinhuang edited a comment on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang edited a comment on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-837266936


   > I'm not yet convinced this is an actual problem in a task run by airflow -- I haven't been able to reproduce this with a python operator
   
   Can you reproduce the example in the original issue? I can confirm that on my end, the output from the subprocess spawned by the python callable can not log into the task logs file but still print out to the terminal. This only happens when the task is executed on Unix OS because it will try to `fork` the process instead of doing `Popen` (Popen works fine).
   
   I used this command to test the output, as I believe this is the command executed by the executor (please do correct me if I'm wrong)
   
   ```bash
   airflow tasks run --local ...
   ```
   
   


-- 
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.

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



[GitHub] [airflow] xinbinhuang edited a comment on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang edited a comment on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-837266936


   > I'm not yet convinced this is an actual problem in a task run by airflow -- I haven't been able to reproduce this with a python operator
   
   Can you reproduce the example in the original issue? I can confirm that on my end, the output from the subprocess spawned by the python callable won't log into the task logs file but still print out to the terminal. This only happens when the task is executed on Unix OS because it will try to `fork` the process instead of doing `Popen` (Popen works fine).
   
   I used this command to test the output, as I believe this is the command executed by the executor (please do correct me if I'm wrong)
   
   ```bash
   airflow tasks run --local ...
   ```
   
   


-- 
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.

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



[GitHub] [airflow] xinbinhuang commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r628846342



##########
File path: airflow/task/task_runner/base_task_runner.py
##########
@@ -105,7 +105,8 @@ def deserialize_run_error(self) -> Optional[Union[str, Exception]]:
         """Return task runtime error if its written to provided error file."""
         return load_error_file(self._error_file)
 
-    def _read_task_logs(self, stream):
+    def _stream_reader(self, stream):
+        """Reading from the stream and log into task logs"""
         while True:
             line = stream.readline()
             if isinstance(line, bytes):

Review comment:
       Thanks for the suggestion! Now I think about it deeper, it might be originated from the period when we need to maintain both python2 and python3. Regardless, as we don't support python2 anymore, we should remove it if there is no other reason to keep it.




-- 
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.

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



[GitHub] [airflow] kaxil commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
kaxil commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-887448837


   @xinbinhuang Can you please fix conflicts and rebase to main 


-- 
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



[GitHub] [airflow] ashb commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r656174331



##########
File path: airflow/task/task_runner/standard_task_runner.py
##########
@@ -82,13 +86,21 @@ def _start_by_fork(self):  # pylint: disable=inconsistent-return-statements
             setproctitle(proc_title.format(args))
 
             try:
+                os.close(rpipe)
+                sys.stdout.flush()
+                # replace fds for the stdout/stderr with the newly created pipe
+                os.dup2(wpipe, 1)
+                os.dup2(wpipe, 2)

Review comment:
       ```suggestion
                   os.dup2(wpipe, sys.__stdout__.fileno())
                   os.dup2(wpipe, sys.__stderr__.filenow())
   ```




-- 
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.

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



[GitHub] [airflow] github-actions[bot] commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-952424287


   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
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



[GitHub] [airflow] github-actions[bot] closed pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #15743:
URL: https://github.com/apache/airflow/pull/15743


   


-- 
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



[GitHub] [airflow] ashb commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
ashb commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-836663985


   I'm not yet convinced this is an actual problem in a task run by airflow -- I haven't been able to reproduce this with a python operator


-- 
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r656174185



##########
File path: airflow/utils/log/logging_mixin.py
##########
@@ -88,6 +88,7 @@ def close(self):
 
         This is a no-op method.

Review comment:
       Can we fix (update docstrings) this ?




-- 
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.

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



[GitHub] [airflow] xinbinhuang edited a comment on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang edited a comment on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-837266936


   > I'm not yet convinced this is an actual problem in a task run by airflow -- I haven't been able to reproduce this with a python operator
   
   Can you reproduce the example in the original issue? I can confirm that on my end, the output from the subprocess spawned by the python callable can not log into the task logs file but still print out to the terminal. The command that I used to test the output is:
   
   ```bash
   airflow tasks run --local ...
   ```
   Correct me if I'm wrong, I believe this is the command executed by the executor.
   
   This only happens when the task is executed on Unix OS because it will try to `fork` the process.
   


-- 
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.

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



[GitHub] [airflow] uranusjr commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r631193609



##########
File path: airflow/task/task_runner/standard_task_runner.py
##########
@@ -82,13 +86,21 @@ def _start_by_fork(self):  # pylint: disable=inconsistent-return-statements
             setproctitle(proc_title.format(args))
 
             try:
+                os.close(rpipe)
+                sys.stdout.flush()
+                # replace fds for the stdout/stderr with the newly created pipe
+                os.dup2(wpipe, 1)
+                os.dup2(wpipe, 2)

Review comment:
       It’s probably better to use `sys.__stdout__.fileno()` and `sys.__stderr__.fileno()`. They are basically always `1` and `2` on POSIX but are at least more readable.




-- 
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.

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



[GitHub] [airflow] uranusjr commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r656182872



##########
File path: airflow/task/task_runner/standard_task_runner.py
##########
@@ -82,13 +86,21 @@ def _start_by_fork(self):  # pylint: disable=inconsistent-return-statements
             setproctitle(proc_title.format(args))
 
             try:
+                os.close(rpipe)
+                sys.stdout.flush()
+                # replace fds for the stdout/stderr with the newly created pipe
+                os.dup2(wpipe, 1)
+                os.dup2(wpipe, 2)

Review comment:
       ```suggestion
                   os.dup2(wpipe, sys.__stdout__.fileno())
                   os.dup2(wpipe, sys.__stderr__.fileno())
   ```
   
   Typo :p




-- 
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.

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



[GitHub] [airflow] xinbinhuang edited a comment on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang edited a comment on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-837266936


   > I'm not yet convinced this is an actual problem in a task run by airflow -- I haven't been able to reproduce this with a python operator
   
   Can you reproduce the example in the original issue? I can confirm that on my end, the output from the subprocess spawned by the python callable won't log into the task logs file but still print out to the terminal. This only happens when the task is executed on Unix OS because it will try to `fork` the process instead of doing `Popen` (Popen works fine). The reason is what I described in the PR description. (Just updated the description with more details so hopefully it's more clear)
   
   I used this command to test the output, as I believe this is the command executed by the executor (please do correct me if I'm wrong)
   
   ```bash
   airflow tasks run --local ...
   ```
   
   


-- 
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.

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



[GitHub] [airflow] uranusjr commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r631182601



##########
File path: airflow/utils/log/logging_mixin.py
##########
@@ -88,6 +88,7 @@ def close(self):
 
         This is a no-op method.

Review comment:
       Not anymore?




-- 
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.

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



[GitHub] [airflow] github-actions[bot] closed pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #15743:
URL: https://github.com/apache/airflow/pull/15743


   


-- 
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



[GitHub] [airflow] potiuk commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-840024859


   Fantastic analysis @xinbinhuang ! 
   
   Just a thought - maybe we could simply switch to directly capturing filedescriptors. This is what Pytest does. Depending on the flags it can capture:
   
   * directly FDs
   * sys.stderr/sys.sdtdout
   * tee-capture (captures sys/stderr and sys.stdout but writes it through to the original sys.*
   
   This is describe here:
   https://docs.pytest.org/en/6.2.x/capture.html#setting-capturing-methods-or-disabling-capturing
   
   And code is here:
   https://github.com/pytest-dev/pytest/blob/main/src/_pytest/capture.py#L253
   
   Maybe that could be an inspiration and we find a better way ?
   


-- 
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.

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



[GitHub] [airflow] github-actions[bot] commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-917297638


   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
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



[GitHub] [airflow] xinbinhuang commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r628824580



##########
File path: airflow/task/task_runner/base_task_runner.py
##########
@@ -119,6 +120,11 @@ def _read_task_logs(self, stream):
                 line.rstrip('\n'),
             )
 
+    def read_task_logs(self, stream):
+        """Start a daemon thread to read subprocess logging output"""
+        log_reader = threading.Thread(target=self._stream_reader, args=(stream,), daemon=True)

Review comment:
       Not sure if `daemon` here is actually good (original behavior). If the program exists before the thread read/send all the logs, we may miss out some logs




-- 
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.

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



[GitHub] [airflow] uranusjr commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-839912666


   I couldn’t come up with anything better. Or anything else *at all*, really; awesome analysis and solution @xinbinhuang.


-- 
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.

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



[GitHub] [airflow] xinbinhuang commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-837266936


   > I'm not yet convinced this is an actual problem in a task run by airflow -- I haven't been able to reproduce this with a python operator
   
   Can you reproduce the example in the original issue? I can confirm that on my end, the output from the subprocess spawned by the python callable can print out to the terminal but not logging into the task logs file.
   


-- 
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.

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



[GitHub] [airflow] xinbinhuang edited a comment on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang edited a comment on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-837266936


   > I'm not yet convinced this is an actual problem in a task run by airflow -- I haven't been able to reproduce this with a python operator
   
   Can you reproduce the example in the original issue? I can confirm that on my end, the output from the subprocess spawned by the python callable won't log into the task logs file but still print out to the terminal. This only happens when the task is executed on Unix OS because it will try to `fork` the process instead of doing `Popen` (Popen works fine). The reason is what I described in the PR description.
   
   I used this command to test the output, as I believe this is the command executed by the executor (please do correct me if I'm wrong)
   
   ```bash
   airflow tasks run --local ...
   ```
   
   


-- 
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.

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



[GitHub] [airflow] xinbinhuang commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r628846342



##########
File path: airflow/task/task_runner/base_task_runner.py
##########
@@ -105,7 +105,8 @@ def deserialize_run_error(self) -> Optional[Union[str, Exception]]:
         """Return task runtime error if its written to provided error file."""
         return load_error_file(self._error_file)
 
-    def _read_task_logs(self, stream):
+    def _stream_reader(self, stream):
+        """Reading from the stream and log into task logs"""
         while True:
             line = stream.readline()
             if isinstance(line, bytes):

Review comment:
       Thanks for the suggestion! Now I think about it deeper, it might originate from the period when we need to maintain both python2 and python3. Regardless, as we don't support python2 anymore, we should remove it if there is no other reason to keep it.




-- 
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.

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



[GitHub] [airflow] uranusjr commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r628842968



##########
File path: airflow/task/task_runner/base_task_runner.py
##########
@@ -105,7 +105,8 @@ def deserialize_run_error(self) -> Optional[Union[str, Exception]]:
         """Return task runtime error if its written to provided error file."""
         return load_error_file(self._error_file)
 
-    def _read_task_logs(self, stream):
+    def _stream_reader(self, stream):
+        """Reading from the stream and log into task logs"""
         while True:
             line = stream.readline()
             if isinstance(line, bytes):

Review comment:
       The only place `_read_task_logs()` is called (before this PR in master), `stream` is the stdout of a `Popen(universal_newlines=True)`, so it can actually never emit bytes anywhere in the code base. And since `_read_task_logs()` is private, any third-party code that relies on it is subject to break anyway.
   
   I would categorise this as *overly defensive* programming in the original implementation and simply remvoe the `if isinstance(line, bytes)` check entirely. It should not have been written in the first place.




-- 
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.

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



[GitHub] [airflow] andrewgodwin commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
andrewgodwin commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-839939006


   Yup, this looks about what I would do given the `fork()` nature.


-- 
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.

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



[GitHub] [airflow] github-actions[bot] commented on pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#issuecomment-996289361


   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
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



[GitHub] [airflow] xinbinhuang commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r628824780



##########
File path: airflow/task/task_runner/base_task_runner.py
##########
@@ -105,7 +105,8 @@ def deserialize_run_error(self) -> Optional[Union[str, Exception]]:
         """Return task runtime error if its written to provided error file."""
         return load_error_file(self._error_file)
 
-    def _read_task_logs(self, stream):
+    def _stream_reader(self, stream):
+        """Reading from the stream and log into task logs"""
         while True:
             line = stream.readline()
             if isinstance(line, bytes):

Review comment:
       I was tempting to rewrite this as:
   ```
   for line in iter(stream.readline, ""):
       ...
   ```
   
   I wonder if both binary and string would get thrown into the stream? so we need to handle both `bytes` and `str` (this is the current assumption)?




-- 
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.

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



[GitHub] [airflow] uranusjr commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r628842968



##########
File path: airflow/task/task_runner/base_task_runner.py
##########
@@ -105,7 +105,8 @@ def deserialize_run_error(self) -> Optional[Union[str, Exception]]:
         """Return task runtime error if its written to provided error file."""
         return load_error_file(self._error_file)
 
-    def _read_task_logs(self, stream):
+    def _stream_reader(self, stream):
+        """Reading from the stream and log into task logs"""
         while True:
             line = stream.readline()
             if isinstance(line, bytes):

Review comment:
       The only place `_read_task_logs()` is called, `stream` is the stdout of a `Popen(universal_newlines=True)`, so it can actually never emit bytes anywhere in the code base. And since `_read_task_logs()` is private, any third-party code that relies on it is subject to break anyway.
   
   I would categorise this as *overly defensive* programming in the original implementation and simply remvoe the `if isinstance(line, bytes)` check entirely. It should not have been written in the first place.




-- 
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.

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



[GitHub] [airflow] xinbinhuang commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
xinbinhuang commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r628824780



##########
File path: airflow/task/task_runner/base_task_runner.py
##########
@@ -105,7 +105,8 @@ def deserialize_run_error(self) -> Optional[Union[str, Exception]]:
         """Return task runtime error if its written to provided error file."""
         return load_error_file(self._error_file)
 
-    def _read_task_logs(self, stream):
+    def _stream_reader(self, stream):
+        """Reading from the stream and log into task logs"""
         while True:
             line = stream.readline()
             if isinstance(line, bytes):

Review comment:
       I was tempting to rewrite this as:
   ```
   for line in iter(stream, ""):
       ...
   ```
   
   I wonder if both binary and string would get thrown into the stream? so we need to handle both `bytes` and `str`?




-- 
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #15743: Redirect forked process output to logger

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #15743:
URL: https://github.com/apache/airflow/pull/15743#discussion_r656174185



##########
File path: airflow/utils/log/logging_mixin.py
##########
@@ -88,6 +88,7 @@ def close(self):
 
         This is a no-op method.

Review comment:
       Can we fix this ?




-- 
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.

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