# How can I stop the function in FormPage from timing out?

I have a FormPage with a function that, on average, takes several seconds to evaluate. This is entirely expected. However, FormPage frequently returns \$Aborted as the result, much like Manipulate does when the computation takes more than a second or two.

I cannot find any option in the official documentation of FormPage that would increase the time available for the computation. Is there any trick or hack that I can use? (Please remember that the function itself cannot be made faster.)

• Are you talking about a form page deployed to WolflramCloud or are you using it in desktop Mathematica? – Kuba Jun 17 '18 at 9:56
• @Kuba thank you very much. I should have clarified in my question that the function times out on the desktop version of Mathematica. So I expect the cloud deployment to be even worse. I'll examine your patch to understand it--but it appears that the answer is to resort to asynchronous behaviour with DynamicBox. Thank you again. – Shredderroy Jun 17 '18 at 18:23

Desktop FormPage interface works, more or less, as follows: "Submit" button validates the input and if it is correct it triggers 'body' which is, again roughly, Dynamic[formfuncion @ input].

Unfortunately that Dynamic is a regular preemptive one, restricted by DynamicEvaluationTimeout to 6 [s]. We need to make it queued (main link) SynchronousUpdating->False. (lookup queued/preemtive evaluations).

There is no public interface for this so let's inject it to the boxes:

queuedFormPageDisplay = (ToBoxes[#] /. DynamicBox[content___] :> DynamicBox[content, SynchronousUpdating -> False] // RawBoxes) &;

queuedFormPageDisplay @ FormPage[
"country" -> "Country"
, (Pause[6]; GeoGraphics[#country]) &
]


WolframCloud front end is completely different and Froms are even more special. There are no FE-Kernel links as we know it. So even if there are waiting time restrictions, it is a completely different story. The only issue that you may face is the limitation of your account, in terms of available cloud credits or evaluation time (don't know what is the default limit).

• This works beautifully! Besides solving the original problem, it has another advantage. It allows me to define the formspec and the function separately, outside of FormPage. When I tried that last night without the patch, the timeouts occurred for almost every input. By placing the definitions inside FormPage I was able to reduce the timeouts to about 50 percent of the inputs. I realise that I am giving anecdotal numbers here, but the code is too long to provide on this forum. – Shredderroy Jun 17 '18 at 18:59
• @Shredderroy I am glad it helps, keep in mind this patch will have no effect, can't be used at all, in CloudDeploy-ed version. – Kuba Jun 17 '18 at 19:00
• indeed, I will remember that. Fortunately, I am doing just a desktop demonstration tomorrow--so I can worry about CloudDeploy later. – Shredderroy Jun 17 '18 at 19:01