Say I have this view:
thr = threading.Thread(target=my_func, args=(request,))
thr.start()#Runs a function that the user should not wait for
return render(request, "my_site")
#Some function that takes 10 second and the user should not wait for this
messages.success(request, "Your meal is ready!")
return render(request, "my_other_site")
What I want to do is; I have a function of which the user should not wait for to complete i.e they should be able to continue browsing, and then when the function is done, I want to show them a message either using
messages or a pop-up box or something third.
Is there a way to do that in Django directly (since it all runs synchronous I can’t think of a way), or what would be the most optimal way ?
Correct, there’s not.
Yeah, thats what I thought as well… /:
But its gonna pe a performance issue I would assume, if I each second need to a server to get new requests
Really depends upon how many concurrent users you’re expecting - and being realistic about that estimate.
A couple hundred users probably wouldn’t be much sweat - and keep in mind that the polling only needs to occur when someone is sitting on a page and not browsing to other pages. If they’re actively browsing, they’re generating far more load on the server than if they’re just sitting and reading.