I have a request to an external API within a view which returns two separate solutions. What I would like to achieve is a pause on the execution (so the results are in memory) and, once the user on the front-end decides which solution to save, the execution continues and the results they chose are saved.
What I’ve initially tried is something like this:
def result_user_wants(request):
request.session[‘user_wants_result’]
return JsonResponse({‘result_user_wants’: 1})
def view_to_pause(request):
while ‘user_wants_result’ not in request.session.keys():
sleep(1)
code_that_saves_result()
Whatever the user decides on the front end is passed to the results_user_wants
view and modifies the session data. What I’m then hoping is that the while loop in view_to_pause
is paused until the key exists. This unfortunately doesn’t work, I think because the request data hasn’t been refreshed due to the pause.
My only other thought is to save both results sets in the database and when the user chooses, the other result set is deleted. Appreciate any other thoughts!