Shared data is best stored in a database.
If you need a global variable for a user session, you want to save it with the session data: here are the details for web.py and for the flask .
If you have a standing process that processes the queue, you can look at starting your server using FastCGI, where your python server can be run in a separate instance from your web server. See how to configure FastCGI for web.py - see if this works, perhaps. The web server will communicate with the python server through its own port, so your python server can continue to work and support any global data.
[edit]
Since you need to exchange variables - you can check flask.g for a flask or web.ctx for web.py. I never used them, so I donβt know if there are any evil consequences or performance issues. I saw an example here that suggested in web.py to do something like:
import web def add_global_hook(): g = web.storage({"counter": 0}) def _wrapper(handler): web.ctx.globals = g return handler() return _wrapper class Hello: def GET(self): web.ctx.globals.counter += 1 return "<h1>Counter: %d</h1>" % web.ctx.globals.counter if __name__ == '__main__': urls = ("/", "Hello") app = web.application(urls, globals()) app.add_processor(add_global_hook()) app.run()
source share