Hello there,
In my django project I perform some Machine Learning operations using GBOML and my algorithm can take up to 800-1000 seconds to perform.
I’m using the concept of Process to allow other users to use the application while the algorithm is running.
The process calls another method to perform all the operations, but it looks like this:
try:
terms_type = request.POST.get('terms')
discount_rate = float(request.POST.get('discount_rate'))
project_lifetime = int(request.POST.get('lifetime_project'))
proc = Process(
target=interface.execute,
kwargs={
'request' : request,
'project_lifetime' : project_lifetime,
'discount_rate' : discount_rate,
'terms_type' : terms_type,
'scenario' : scenario,
}
)
proc.run()
scenario.last_run_date = datetime.now()
scenario.save()
except InfeasibleOptimizationException as e:
logger.exception(f'InfeasibleOptimizationException raised in scenario {scenario.id}')
messages.error(self.request, e.message)
return HttpResponseRedirect(reverse('optimization:scenario-second', kwargs={'scenario_id': scenario_id}))
except ValueError as e:
logger.exception(f'ValueError raised in scenario {scenario.id}')
messages.error(self.request, _('An error occured in your optimization. Please review your params'))
return HttpResponseRedirect(reverse('optimization:scenario-second', kwargs={'scenario_id': scenario_id}))
except Exception as e:
logger.exception(f'Exception raised in scenario {scenario.id}')
messages.error(self.request, _('An error occured in your optimization. Please review your params'))
return HttpResponseRedirect(reverse('optimization:scenario-second', kwargs={'scenario_id': scenario_id}))
return HttpResponseRedirect(reverse('optimization:results', kwargs={'scenario_id': scenario_id}))
The thing is, when my code takes around 300-400 seconds, everything’s good, at the end I am returned to the optimization:results route. But when the operation takes up to 800-1000 seconds (around those numbers), the process ends as I can see the results files created in my media folders, but I am never redirected to the optimization:results route. Instead, my browser shows an ERR_CONNECTION_CLOSED error.
The user needs to refresh the tab, go back to the home page and select the specific scenario to see the results (and it works). But it should automatically redirect to the results page and not show the ERR_CONNECTION_CLOSED error…
What should I change ?
Appreciate your help !