0

I use uWSGI with the gevent loop. I also have a function that updates a python dictionary once a minute from a hash stored redis.

My requests in real time need to have access to that hash.

Here is my uWSGI function the loads the hash every 60 seconds.

def loadRedisDict():
    global data
    data = r.hgetall('data')

from uwsgidecorators import *
    @rbtimer(60)
    def load_redis(signum):
        loadRedisDict() 

@post('/test')
@post('/test/')
def test(): 
   print data['foo']
   yield 'test'

I notice that even though the dict is updated, not all requests honor the content of what is in that hash. Even if I have a empty hash request are serving contents in a prev hash. So....what am I missing?

Tampa
  • 75,446
  • 119
  • 278
  • 425

1 Answers1

2

I suppose you are running in multiprocessing mode, so only one process at time will get its dictionary updated.

There is a trick:

@rbtimer(60, target='workers')

will run the timer handler in all of the workers every time.

roberto
  • 12,723
  • 44
  • 30