Issues with data table lookups when running a Telegram bot from a Background Task

This is the answer an old post of mine. I was trying to create a background task when background tasks in anvil did not exist yet. You may find some interesting info about threads in Anvil (assuming that that info is still current).

By using http endpoints I meant getting whatever service you are using to call you back via an http end point rather than generating a thread that waits for that service to respond. I don’t know your library and it may be impossible, I just thought I would mention it.

As I said I stopped using threads before background tasks in Anvil even existed, but you could try to start a background task from your thread. The context (whatever that is) is wrong for working with the database in your own thread, but you could be lucky and you could be able to have your background task start a thread that starts a new background task with the correct context.

Or get your thread to call your http endpoint.

Whether you use a background task or http end point, I’m afraid you will need to serialize your data.

1 Like