tanelk commented on code in PR #23944:
URL: https://github.com/apache/airflow/pull/23944#discussion_r883944216
##########
airflow/executors/local_executor.py:
##########
@@ -365,34 +154,42 @@ def execute_async(
executor_config: Optional[Any] = None,
) -> None:
"""Execute asynchronously."""
- if not self.impl:
+ if not self.futures_executor:
raise AirflowException(NOT_STARTED_MESSAGE)
self.validate_command(command)
- self.impl.execute_async(key=key, command=command, queue=queue,
executor_config=executor_config)
+ result = self.futures_executor.submit(_execute_work, key=key,
command=command)
+ self.futures[result] = key
- def sync(self) -> None:
+ def sync(self, timeout=0) -> None:
"""Sync will get called periodically by the heartbeat method."""
- if not self.impl:
- raise AirflowException(NOT_STARTED_MESSAGE)
- self.impl.sync()
+ try:
+ done, _ = concurrent.futures.wait(self.futures, timeout=timeout)
+ for future in done:
+ key = self.futures.pop(future)
+ exc = future.exception()
+ result: Any
+ if exc:
+ result = (key, State.FAILED, exc)
+ else:
+ result = future.result()
+ self.change_state(*result)
+ except concurrent.futures.TimeoutError:
+ pass
def end(self) -> None:
- """
- Ends the executor.
- :return:
- """
- if not self.impl:
- raise AirflowException(NOT_STARTED_MESSAGE)
- if not self.manager:
+ """Ends the executor."""
+ if not self.futures_executor:
raise AirflowException(NOT_STARTED_MESSAGE)
self.log.info(
"Shutting down LocalExecutor"
"; waiting for running tasks to finish. Signal again if you don't
want to wait."
)
- self.impl.end()
- self.manager.shutdown()
+ self.futures_executor.shutdown()
+ self.sync(timeout=None)
def terminate(self):
"""Terminate the executor is not doing anything."""
+ if self.futures_executor:
+ self.futures_executor.shutdown(wait=False)
Review Comment:
Should we set `cancel_futures=True` in either of the shutdown calls.
--
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]