Timeout on Background task. looks like is_completed() is the culprit

How Folks,

I am getting a timeout using a Background Task and I am stumped.

Here is the log file from Background Task Log.

load_log_entries_bg done. 8852 rows: delta 13.3538 
anvil.server.TimeoutError: Server code took too long

Here is the BG Task code:

@anvil.server.background_task
def load_log_entries_bg(**kwargs):
  a = perf_counter_ns()
  
  log_entries = get_log_entries(**kwargs)
  anvil.server.task_state['log_entry_list'] = log_entries
  # GlobalCache.global_dict['log_entries'] = data_list  
  print(f"load_log_entries_bg done. {len(log_entries)} rows: delta {(perf_counter_ns() - a) / 1e9:.4f} ")

Based on the log statement, the BG task completed in ~13 seconds.

On the Client the exception is

anvil.server.InternalError: The background task failed.
at A_Main_Navigation, line 210
called from A_Main_Navigation, line 210
called from app/anvil_extras/utils/_timed.py:41 

Line 210 is…

      if (all([t.is_completed() for t in self.bg_task_list]) 
          and all([c.visible for c in components[1:]])):

I run 3 background tasks in parallel, one for high-priority data, one for the biggest data set, and one for 8 other sets of reference data.

App starts with components hidden, as data becomes available I toggle them visible = True.

It looks like t.is_completed() is timing out, as that seems to be the only server call.

Any other thoughts? Could I inadvertently be doing something wrong?

Any help appreciated!

Cheers,
Tyler

Thanks for reporting. Are you able to provide a clone link so we can take a look?

@stucork Sent you a DM

1 Like