title: Update request.session variable before function ends
body: <p>At a Django server, I have a page with a single button that starts a function.
  This function takes a while to complete, and I tried writing updates on the process to a request.session variable with the intent of checking on its contents from a separate page. 
  It seems however that request.session variables are not updated until the function they are included in are done. At least the variable does not update until then. 
  Am I right, and if so, is there a way to write to request.session variable before the function's completion?</p>
  
  <p>The sessions are set up properly, I can write and read variables with other examples. For now I'll also just make a temporary db record to store the status update info and read it from there, but I'm curious as of this request.session thing - is my guess correct, and is there a way around?</p>
  
  <p>update: </p>
  
  <p>views.py</p>
  
  <pre><code>@login_required
  def autolink(request):
      result, time = access_check(request, 'super')
      if not result:
          return redirect('index')
      result = f_autolink(request)
      if result is None:
          result = request.session.get('technical', '')
      return render(request, 'autolink.html', {'result': result, })
  </code></pre>
  
  <p>functions.py</p>
  
  <pre><code>def f_autolink(request):
      if request.method == 'GET':
          result = None
      elif request.method == 'POST':
          request.session['technical'] = 'starting the job'
          result = f_kzd_autolink(request)
      else:
          result = None
      return result
  
  def f_kzd_autolink(request):
      homeless = Kzd.objects.filter(payment__isnull=True, returned=False).distinct()
      result = []
      count = homeless.count()
      counter = 0
      request.session['technical'] = 'Starting link job - {c} records to process'.format(c=count)
      for h in homeless:
          counter += 1
          request.session['technical'] = 'Checking record {c1} of {c}'.format(c1=counter, c=count)
  /* long code that makes the h in homeless cycle run for about 3 minutes, unrelated to the question */
  </code></pre>
  
  <p>so basically, the view shows request.session.get('technical', ''), but neither function writes to it until they are done (it then writes about processing the last record).</p>