alert-oil-1341
11/08/2024, 9:12 PMAsyncAgentExecutorMixin
code, the delete method is scheduled in the signal_handler, which is only called when a signal SIGINT is emitted. This is preventing resource clean up as part of normal execution (without any interruptions) and is preventing one of our test cases from progressing.
What are thoughts on simply making this a final step in the execution, ensuring we get to that code every time? Something like:
def execute(self: PythonTask, **kwargs) -> LiteralMap:
ctx = FlyteContext.current_context()
ss = ctx.serialization_settings or SerializationSettings(ImageConfig())
output_prefix = ctx.file_access.get_random_remote_directory()
from flytekit.tools.translator import get_serializable
task_template = get_serializable(OrderedDict(), ss, self).template
self._agent = AgentRegistry.get_agent(task_template.type, task_template.task_type_version)
resource_meta = asyncio.run(
self._create(task_template=task_template, output_prefix=output_prefix, inputs=kwargs)
)
try:
# Main execution logic
resource = asyncio.run(self._get(resource_meta=resource_meta))
if resource.phase != TaskExecution.SUCCEEDED:
raise FlyteUserException(f"Failed to run the task {self.name} with error: {resource.message}")
# Process outputs
if task_template.interface.outputs and resource.outputs is None:
local_outputs_file = ctx.file_access.get_random_local_path()
ctx.file_access.get_data(f"{output_prefix}/outputs.pb", local_outputs_file)
output_proto = utils.load_proto_from_file(literals_pb2.LiteralMap, local_outputs_file)
return LiteralMap.from_flyte_idl(output_proto)
if resource.outputs and not isinstance(resource.outputs, LiteralMap):
return TypeEngine.dict_to_literal_map(ctx, resource.outputs)
return resource.outputs
finally:
# Cleanup logic that runs after the try block, even if it returns or raises an exception
try:
asyncio.run(self._agent.delete(resource_meta=resource_meta))
except Exception as e:
logger.error(f"Error during resource cleanup: {e}")
damp-lion-88352
11/12/2024, 8:32 AMdamp-lion-88352
11/12/2024, 8:32 AMdamp-lion-88352
11/12/2024, 8:32 AMdamp-lion-88352
11/12/2024, 1:16 PMget
reach a terminal state, why we need to delete it?damp-lion-88352
11/12/2024, 1:17 PMalert-oil-1341
11/12/2024, 1:18 PMalert-oil-1341
11/12/2024, 1:53 PMdamp-lion-88352
11/12/2024, 1:54 PMdamp-lion-88352
11/12/2024, 1:54 PMget
methodalert-oil-1341
11/12/2024, 1:55 PMdamp-lion-88352
11/12/2024, 1:55 PMalert-oil-1341
11/12/2024, 1:55 PMdamp-lion-88352
11/12/2024, 1:56 PMalert-oil-1341
11/12/2024, 1:56 PMdamp-lion-88352
11/12/2024, 1:56 PMalert-oil-1341
11/12/2024, 1:56 PMdamp-lion-88352
11/12/2024, 1:57 PMalert-oil-1341
11/12/2024, 1:57 PMdamp-lion-88352
11/12/2024, 1:57 PMdamp-lion-88352
11/12/2024, 1:57 PMdamp-lion-88352
11/12/2024, 1:57 PMdamp-lion-88352
11/12/2024, 1:57 PMalert-oil-1341
11/12/2024, 1:58 PMdamp-lion-88352
11/12/2024, 1:58 PMdamp-lion-88352
11/12/2024, 1:58 PMdamp-lion-88352
11/12/2024, 1:58 PMdamp-lion-88352
11/12/2024, 1:58 PM