简体   繁体   English

龙卷风:所有IOLoop实例的全局变量

[英]Tornado: global variable for all IOLoop instances

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 eg ban someone. 我有一个简单的龙卷风/雷迪斯聊天,其中有一个带有侦听器的池(简单的字典,用户名作为键,websocket对象作为值),因此(可以说是主持人)可以修改用户的websocket对象,例如禁止某人。 But when I launched multiple IOLoop instances, I suddenly realized that this pool isn't global anymore. 但是,当我启动多个IOLoop实例时,我突然意识到该池不再是全局的。 So the question is, is it possible to have something like shared variable between all IOLoops? 因此,问题是,是否可能在所有IOLoop之间使用共享变量之类的东西? I have tried to make this pool a part of Application before forking IOLoop like this: 在分叉IOLoop之前,我试图使此池成为Application的一部分:

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

But it didn't work. 但这没有用。

To share data among distinct Python processes, the data must be stored in some central process like the database server. 要在不同的Python进程之间共享数据,必须将数据存储在某些中央进程(如数据库服务器)中。 I suggest putting your shared data in Redis, since you're already using it. 建议您将共享数据放入Redis,因为您已经在使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM