title: nginx + uwsgi + flask and multiprocess
body: <p>I have I python-flask script running under uwsgi + nginx deployment configuration. 
  My uwsgi.ini file:</p>
  
  <pre><code>[uwsgi]
  pythonpath=/usr/bin/python3
  socket=/tmp/grace.sock
  chmod-socket = 666
  vacuum = true
  uid = www-data 
  gid = www-data
  plugin= python3
  chdir= /home/grace/pyRep/beta_grace
  module= app:app
  enable-threads= true
  master= true
  processes= 3
  #cheaper= 1
  logto = /home/grace/pyRep/beta_grace/uwsgi.log
  lazy-apps = true
  single-interpreter=true
  </code></pre>
  
  <p>now, inside my script I have a function like this:</p>
  
  <pre><code>from uwsgidecorators import *
  
  @timer(60)    
  def foo():
      global_var += 1
      print(global_var)
  </code></pre>
  
  <p>Looking at my logs i find:
   global_var: 1
   global_var: 1
   global_var: 1</p>
  
  <p>In my opinion this is due to the lazy-apps options enabled, so after fork i have three copies of this task running and after some time I find:</p>
  
  <p>global_var: 34
  global_var: 32
  global_var: 32</p>
  
  <p>I tried with the @lock and @postfork decorator before @timer decorator but nothing changes. If I take out lazy-apps option I have problems connecting to the mongoDB engine and other weird behaviours so I think that I have to keep it. 
  The only solution I found is to limit processes to 1 but this obiouvsly decreases performances. 
  Any advice?!</p>