python - access/update global/shared defaultdict from different tornado.RequestHandler instances -


is safe access/update global defaultdict different requesthandler instances? e.g.

globalmap = defaultdict(list)  class event(tornado.web.requesthandler):     def get(self, unit):         # access/modify might happen         # list.append() arbitrary example         globalmap[unit].append(datetime.utcnow())          self.write(b'')  

if not, what’s proper way lookup/store of keyed data between different requesthandler instances?

yes, that's fine do. tornado code typically runs in main thread; code accesses python data structure this.

however, if you're deploying tornado application in production you'll want multiple tornado processes, maybe running on multiple machines, you'll want put data in shared database server share among processes.


Comments