gevent 多个 StreamServer 监听器
我有一个守护进程,它有到 handlerSocket 的连接池。我有两种类型的客户端,它们的协议不同。我想设置 2 个监听器来处理每个协议并在它们之间共享连接池。在 Twisted 中,这相对容易完成,但在 gevent 中找不到如何做到这一点。 谢谢!
I have daemon which has connection pool to handlerSocket. I have 2 types of clients and their protocol differs. I want to setup 2 listeners which handles each protocol and shares connection pool between them. In twisted this is relatively easy to accomplish, but couldn't find out how to do this in gevent.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
StreamServer 的第一个实例可以通过 server.start() 启动,第二个实例可以通过 server2.serve_forever() 启动
first instance of StreamServer could be started with: server.start() and second with server2.serve_forever()
除了 frx 的答案之外,这里还有一个管理多个服务器的类: https://gist.github.com/1008826
In addition to frx's answer, here's a class to manage multiple servers: https://gist.github.com/1008826
我认为问题出在 StreamServer 的 stop() 方法上。
它会杀死池,因此,完成其中一个侦听器将删除两个侦听器的所有连接。
如果这并没有吓到您,您可以简单地将相同的 Pool 对象传递给两个 StreamServer,并在单独的 greenlet 中运行它们。
I think the problem will come from the StreamServer's stop() method.
It kills the pool, so, finishing one of listeners will drop all connections, from both listeners.
If this is does not frighten you, you can simply pass the same Pool object to both StreamServers, running each of them in the separate greenlet.