Transaction expiring randomly in background task

I was using the get_return_value method of the task object. This returns anything the task returns, or None if the task is incomplete.

Is it better to use the state vs the return value? I am pinging the task in a timer for get_termination_status() and calling the return value. I didn’t know if using the state was better practice.

Here is the code:

def check_data_is_loaded(self):
      with anvil.server.no_loading_indicator:
        term_status = None
        term_status = self.task.get_termination_status()
        if term_status == "completed":
          data = self.task.get_return_value()
          if data is not None:
            self.set_data(data)
            self.complete_init_flag = True   

This is called by a timer and I reset term_status to None, because I was noticing it still being set to a value when being called.