Tornado: global variable for all IOLoop instances

580 Views Asked by At

I have a simple tornado/redis chat that has a pool with listeners(simple dict with username as key and websocket object as value) so one(let's say moderator) could modify users websocket objects to e.g. ban someone. But when I launched multiple IOLoop instances, I suddenly realized that this pool isn't global anymore. So the question is, is it possible to have something like shared variable between all IOLoops? I have tried to make this pool a part of Application before forking IOLoop like this:

app = Application()
app.listeners = {}
http_server = HTTPServer(app)
http_server.bind(8181)
http_server.start(0)

But it didn't work.

1

There are 1 best solutions below

0
A. Jesse Jiryu Davis On BEST ANSWER

To share data among distinct Python processes, the data must be stored in some central process like the database server. I suggest putting your shared data in Redis, since you're already using it.