python - Time out issues with chrome and flask -
i have web application acts interface offsite server runs long task. user enters information , hits submit , chrome waits response, , loads new webpage when receives it. depending on network, input of user, task can take pretty long time , chrome loads "no data received page" before data returned (though task still running).
is there way put either temporary page while task thinking or force chrome continue waiting? in advance
while change timeout on server or other tricks try keep page "alive", keep in mind there might other parts of connection have no control on timeout request (such timeout value of browser, or proxy between browser , server, etc). also, might need timeout value if task takes longer complete (becomes more advanced, or slower because more people use it).
in end, sort of problem typically solved change in architecture.
use separate process long-running tasks
rather submitting request , running task in handling view, view starts running of task in separate process, returns response. response can bring user "please wait, we're processing" page. page can use 1 of many push technologies out there determine when task completed (long-polling, web-sockets, server-sent events, ajax request every n seconds, or dead-simplest: have page reload every 5 seconds).
have web request "kick off" separate process
anyway, said, view handling request doesn't long action: kicks off background process task it. can create background process dispatch (check out this flask snippet possible ideas), or use library celery or (rq).
once task complete, need way of notifying user. dependent on sort of notification method picked above. simple "ajax request every n seconds", need create view handles ajax request checks if task complete. typical way have long-running task, last step, make update database. requests checking status can check part of database updates.
advantages , disadvantages
using method (rather trying fit long-running task request) has few benefits:
1.) handling long-running web requests tricky business due fact there multiple points time out (besides browser , server). method, web requests short , less timeout.
2.) flask (and other frameworks it) designed support number of threads can respond web queries. assume has 8 threads: if 4 of them handling long requests, leaves 4 requests handle more typical requests (like user getting profile page). half of web server tied doing not serving web content! @ worse, have 8 threads running long process, meaning site unable respond web requests until 1 of them finishes.
the main drawback: there little more set work in getting task queue , running, , make entire system more complex. however, highly recommend strategy long-running tasks run on web.
Comments
Post a Comment