uranusjr commented on a change in pull request #20470:
URL: https://github.com/apache/airflow/pull/20470#discussion_r774923091
##########
File path: airflow/dag_processing/processor.py
##########
@@ -149,8 +149,8 @@ def _run_file_processor(
try:
# redirect stdout/stderr to log
- with redirect_stdout(StreamLogWriter(log, logging.INFO)),
redirect_stderr(
- StreamLogWriter(log, logging.WARN)
+ with redirect_stdout(StreamLogWriter(log, logging.INFO)), (
+ redirect_stderr(StreamLogWriter(log, logging.WARN))
), Stats.timer() as timer:
Review comment:
This does not work because [you can’t use parentheses in a `with`
statement like anywhere else in the language, until
3.10](https://bugs.python.org/issue12782) 😞
A popular workaround is
```python
import contextlib
with contextlib.ExitStack() as stack:
stack.enter_context(redirect_stdout(StreamLogWriter(log, logging.INFO)))
stack.enter_context(redirect_stderr(StreamLogWriter(log, logging.WARN)))
timer = stack.enter_context(Stats.timer())
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]