Background task not running

What I’m trying to do:
I am working with pandas dataframes and since they are quite big I am testing the method as a background task.

On the side window, it shows that the task is running, but it does not seem to run at all.
Here is my code, I have a timer that I use to display the index, just to check if it is running at all but the only print I get is a 0, which means that it does not even get to the first line of the background task.

image
image

What I’ve tried and what’s not working:
I have tested it with a background task that just loops through a for loop and everything was working fine. I am starting to think it could be a problem with the file.

it might not be the problem but it looks like you’ve got your if and else bodies the wrong way round…

df = pd.read_csv # should be read_excel

I have actually tested that and for some reason, Anvil recognizes .csv files as ‘application/vnd.ms-excel’. However, this is not the problem, as it does not even execute the first line of the background task where I set the state[‘index’] to 5.

Here is a copy of my application.
https://anvil.works/build#clone:FCCQXIGBTQEODQIJ=WM2YZAYIF3VMQCAZ5BRR4DVO

It is somewhat big, so the code that you are looking for is in the ‘file_service’ server module and in the MatchForm where I have a timer for testing and an upload button.

The best approach for debugging background tasks is to add print statements and take a look at your logs.

When I do that with your clone I get - NameError: pd is not defined

1 Like

Oh, I am sorry, I have send the wrong version, you need you add
import pandas as pd
import anvil.media
in file_service. I think that the problem is coming from the file, because I also have a print statement, but the background task seem to run forever and in my logs I dont have any prints, its like the task is not starting at all.

Running the code and adding those import statements worked fine for me.
I created a 2 row csv with the headers and both rows were successfully added.
I included some extra logging in the background tasks.
You might want to try smaller files and see if that makes a difference.

Adding print statement and various execution points in the background task might help to work out what code does get executed.

1 Like

Thank you, I have also tested it and it seems to be because of the file size.

1 Like

I have one more question. Do you think there will be a way to go around this? My application will work with files that have more than 10 000 rows, which is one of the core functionalities.