Anvil server timeout, after less then 1 min

What I’m trying to do:
I created a code in Anvil in the server side and after running the GUI I get:
anvil.server.TimeoutError: Server code took too long
It seems that Anvil has a time limit of 30 sec?
If so how can I increase this time limit?

You can’t, and very likely you don’t need to.

Have you tried to go through some tutorials first, so you understand how Anvil works?

1 Like

it seems that after digging in the forum it is possible by using @jshaffstall answer:
TIMEOUT = int(os.environ.get(“DOWNLINK_WORKER_TIMEOUT”, “30”))
That indeed work.
However it seems that every button that is pressed in the GUI, the code start all over again and it takes too much time. (Even though most of the code is not under the @anvil.server.callable)
Is there a way to put some code in cache?

I’ll try again: Have you tried to go through some tutorials first, so you understand how Anvil works?

The post you pulled that from was about running the Anvil open source server on your own hardware, not using the Anvil hosted service. If you’re running the Anvil hosted service, you shouldn’t be trying to modify the timeout. Instead, optimize your code and use the features Anvil provides (background tasks, timers, etc). There are a lot of forum posts on optimizing server code you should read over, they give good advice.

1 Like

The background task is not an option, as I can’t let the user interact with the GUI until everything is ready.
The timeout worked and stretched the timeout barrier. However, every button press takes forever, even when the files are already in the tmp dir.
( Does Anvil run the server code all over again for every interaction? Even if most of the code is not decorated? )

If you have some tutorial to start from, that will be helpful.
( I know there is some cache options available in Streamlit and I wonder if they exist here as well )

The background task is the only option for tasks that last longer than 30 seconds.

You can disable the buttons and other UI elements while a timer in the form polls the server and checks whether the background task is done, then re-enable them when it’s done.

If you click on the question mark at the top right, you will see plenty of tutorials.

EDIT
Here is a little advice: instead of thinking “Anvil is wrong, I need to change its timeout limit because I need it”, try to think “Do I really need it? There are thousands of users out there that already went through this, let me ask them how they solve this problem”.

3 Likes

That is an incorrect conclusion. There is no relationship between background tasks and the GUI, you can make them work however you want.

I’m sorry, but I’m not going to search the forum for you to link other posts about the same topic. You’ll have to put that time in yourself.

1 Like

I can’t let the user interact with the GUI while the background tasks run, as every button he will press will raise an error as the files are not ready.

What @stefano.menci suggested is nice idea to lock the GUI.

but that is also highly unusable and not friendly, as the user will have to stare at the screen a min or so and won’t be able to interact with the system.

A better way to do it is to one time load the GUI for 1 min. And then cache the files for the rest of the interaction, is that possible?
Currently It seems that every button press all the code is running from scratch again.

Please try to ask better question, or we will start associating your name to bad questions and stop even trying to answer.

We like to help people with their problems, we don’t like to waste time trying to understand their problems.

Here are a couple of links to the how to ask a good question or the worked example of how to turning an unhelpful question into a good one.

You are saying my code is slow, but you are not showing the code.
You are saying cache the files, but you don’t say what are the files.

Those two quotes are from the same post. At this point we have no idea what your design requirements are, because you’re contradicting yourself.

Please spend some time thinking about how you want the GUI to work. Not from an Anvil perspective, but just in general. Do simple sketches on what the flow looks like to the user, so you know what you’re trying to accomplish and can communicate that.

When you know how you want the GUI to flow, start a new topic for advice on how to make that happen, since none of the recent activity on this post has anything to do with the server timeout, which is the subject of the post.

Or you mean please ask easier questions, since your questions are hard to answer?
I can’t show the code for obvious reasons.
And certainly I can’t show you the files that I am using,
I think that my questions are pretty clear, and I try to make them as general as possible so other people can benift from the answers.
If some information is missing from my questions you are welcome to ask for them.

No, I mean please ask better quesions.
Your questions are difficult to understand because they don’t provide enough information, not to answer.

No, there are no obvious reasons. If you can’t show the “real” code, you can always crate a “simplified” version of the code that reproduces the same problem. That’s often the very definition of asking a good question easy to understand.

I and others have spent more time asking you to go through tutorials and asking more info about your bad questions than answering questions. You obviously have not even tried to read the links we have given you that show how to ask a good question. Think about it: if you are here asking and we are here answering, and you are trying to tell us we are wrong and you are right.

Good luck finding answers.

Hi all,

There are plenty of existing topics on server timeouts already on this forum (just search ‘server timeout’!), and this thread seems to be going around in circles, so I am closing it. A few things to note:

  1. If you are new to Anvil, this forum is a great place to get answers, but not a great place to start. We recommend our Feedback Form tutorial as a good introduction to the basics. We have plenty of other tutorials to try after that, many about specific features: Anvil | Tutorials.
  2. Many answers are already in our documentation! This is the best place to go first when learning how to use Anvil features: Anvil Docs | Overview
  3. There is a Help Tab within the Anvil Editor that links to useful resources to help you get started and level up your skills. You can also search the knowledge base from there. This searches the documentation, tutorials and the forum.
  4. There are a lot of smart people on this forum who love Anvil and really want to help. But it’s really hard to help without providing context and code. Please be as specific as possible in your questions and what you are trying to do. Provide code snippets and in more complex cases, a minimal app that shows the issue you’re facing. You can then provide a clone link to this minimal example.
10 Likes