kaxil commented on code in PR #51023:
URL: https://github.com/apache/airflow/pull/51023#discussion_r2105763025


##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -685,7 +685,9 @@ def _service_subprocess(
         :param expect_signal: Signal not to log if the task exits with this 
code.
         :returns: The process exit code, or None if it's still alive
         """
-        events = self.selector.select(timeout=max_wait_time)
+        # Ensure minimum timeout to prevent CPU spike with tight loop when 
timeout is 0 or negative
+        timeout = max(0.01, max_wait_time)
+        events = self.selector.select(timeout=timeout)

Review Comment:
   This change could have been in `_monitor_subprocess(` but 
`_service_subprocess` is called from 2 places: 1) `_monitor_subprocess(` and 
`kill` ( 
[code](https://github.com/apache/airflow/blob/65fac1a9fa5fee59ff88aaddcd7a6154bd348dd8/task-sdk/src/airflow/sdk/execution_time/supervisor.py#L596)
 ) -- so I did it here
   
   
https://github.com/apache/airflow/blob/65fac1a9fa5fee59ff88aaddcd7a6154bd348dd8/task-sdk/src/airflow/sdk/execution_time/supervisor.py#L876C9-L895



##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -685,7 +685,9 @@ def _service_subprocess(
         :param expect_signal: Signal not to log if the task exits with this 
code.
         :returns: The process exit code, or None if it's still alive
         """
-        events = self.selector.select(timeout=max_wait_time)
+        # Ensure minimum timeout to prevent CPU spike with tight loop when 
timeout is 0 or negative
+        timeout = max(0.01, max_wait_time)
+        events = self.selector.select(timeout=timeout)

Review Comment:
   This change could have been in `_monitor_subprocess(` but 
`_service_subprocess` is called from 2 places: 1) `_monitor_subprocess(` and 
`kill` ( 
[code](https://github.com/apache/airflow/blob/65fac1a9fa5fee59ff88aaddcd7a6154bd348dd8/task-sdk/src/airflow/sdk/execution_time/supervisor.py#L596)
 ) -- so I did it here
   
   
https://github.com/apache/airflow/blob/65fac1a9fa5fee59ff88aaddcd7a6154bd348dd8/task-sdk/src/airflow/sdk/execution_time/supervisor.py#L876-L895



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

Reply via email to