this is a different aproach for the question I already asked
Simultaneous multitasking in Django
so it will share the intro.
I have in my web project a time consuming function. While the function is doing its computations, a web page should be rendered informing the user that the results will be sent by email once the computation is done.
views.py:
def web_function(request):
...
return HttpResponse(results_will_be_sent_by_mail.html)
time_consuming_function()
Since the page that has to be rendered is quite simple, and it requires no return information from time_consuming_function() is there a way to skip multitasking and just somehow first render and show the page and than call time_consuming_function()?
Possible solution:
- When the input button is pressed on the page that precedes the calling of “web_function”, attach some javascript code which will render the temporary page?
Update
Ended up using celery. Wasn’t successful in experimenting with Ajax.
A return statement in a function represents the end of that function.* Your snippet’s time_consuming function is outside the function’s scope and thus will never be reached.
A solution for handling the task could be: celery which is well suited for wrapping functions as asynchronous tasks. If you must do things synchronous, why don’t you use ajax for this so you can atleast show the user what’s going on with a BeforeSend?
*This is true for Python and most, if not all, object oriented programming languages