How to limit time execution of a function ? Modification of gluon ?

40 views
Skip to first unread message

Pascal Véron

unread,
Jan 20, 2021, 1:19:38 AM1/20/21
to web2py-users
Hello,

here is my problem : lets' assume that i connect to the following URL :


and that the myfunc function in default.py makes a call to a function f(param) which could take a long time depending on the value of param. I wan't to stop my function f() if it's time execution exceeds 3 seconds. In that case i wan't to send a flash message which contains the message "Time limit exceeded"

Can you help me. I tried to use SIGALRM but wsgi does not allow to trap signals. I changed the default option in wsgi to catch SIGALRM but the i have an error which says that the signal function can only be used in the main thread which is the restricted.py script in gluon directory. Do i need to modify this script ?

Thanks for your help


Dave S

unread,
Jan 26, 2021, 12:22:08 AM1/26/21
to web2py-users
On Tuesday, January 19, 2021 at 10:19:38 PM UTC-8 veron.p...@gmail.com wrote:
Hello,

here is my problem : lets' assume that i connect to the following URL :


and that the myfunc function in default.py makes a call to a function f(param) which could take a long time depending on the value of param. I wan't to stop my function f() if it's time execution exceeds 3 seconds. In that case i wan't to send a flash message which contains the message "Time limit exceeded"


Would it be better to use the scheduler?  One of its purposes is to deal with long-running processes without holding up the response to the user.  The work flow might be to have myfunc queue a worker and pass param to it, return a "pending result" to the user, and then use jquery and a client-side timer to poll for results.

Can you help me. I tried to use SIGALRM but wsgi does not allow to trap signals. I changed the default option in wsgi to catch SIGALRM but the i have an error which says that the signal function can only be used in the main thread which is the restricted.py script in gluon directory. Do i need to modify this script ?

Thanks for your help

Browsers have been known to give timeout messages of some sort if the server takes too long.

/dps
 

Dave S

unread,
Jan 26, 2021, 12:25:43 AM1/26/21
to web2py-users
On Monday, January 25, 2021 at 9:22:08 PM UTC-8 Dave S wrote:
On Tuesday, January 19, 2021 at 10:19:38 PM UTC-8 veron.p...@gmail.com wrote:
Hello,

here is my problem : lets' assume that i connect to the following URL :


and that the myfunc function in default.py makes a call to a function f(param) which could take a long time depending on the value of param. I wan't to stop my function f() if it's time execution exceeds 3 seconds. In that case i wan't to send a flash message which contains the message "Time limit exceeded"


Would it be better to use the scheduler?  One of its purposes is to deal with long-running processes without holding up the response to the user.  The work flow might be to have myfunc queue a worker and pass param to it, return a "pending result" to the user, and then use jquery and a client-side timer to poll for results.

You may also be able to have the worker do a push notification of the results, but that's not any area I have experience with. 
Reply all
Reply to author
Forward
0 new messages