Time limit issue while importing a csv file into DateTable

I have followed some guidelines to import my data in to a datatable. My csv is 1.2MB, not sure if I am hitting a limit here.

My code taken from here:

@anvil.server.callable
def create_datatable():
    # read file from datatable
    my_media = app_tables.files.get(id=1)['results']

    # parse it into a pandas dataframe
    df = pd.read_csv(io.BytesIO(my_media.get_bytes()), header=0,\
               names=['colA', 'colB', 'colC', 'colD', 'colE', 'colF', 'colG'])

    # create list of dict for automatic insertion in table
    list_of_dicts=df.to_dict('records')

    # insert into new data table
    for d in list_of_dicts:
        app_tables.results.add_row(**d)

Cannot complete due to a time limit error… is there a way to avoid this limitation?

Hi @simone, background task will help

Hi Simone - you’ll definitely need to explore background tasks. It’s fairly straightforward to implement, took me a little bit to work out communicating between the background task and the server task. Also, if. you’ve not ‘discovered’ the App Logs, you’ll need to because anything that goes wrong in the background task will not show up in ‘Output’ like you’re accustomed to… Also, your debugging print statements in your background task will appear in the Apps Logs. Lemme know if you need/want an example

2 Likes

Hi thanks very much, that’s the pointer I needed.