当多个进程共享侦听套接字时,为什么新进程条目然后旧进程的事件停止运行?
问题发生在我的代理程序中,考虑到 G10K,我在程序中使用 gevent,并使用低级 gevent.core 来运行我的所有函数。
在我将程序更改为多个进程之前。一切都好。但是当我改变它时,问题就出现了。
我发现问题是当进程NO.2接受套接字时,进程NO.1的事件将停止调度。如果我在我的事件中添加睡眠(0.1),则会带来惊喜。但我降低了睡眠时间,问题又出现了。
这个问题困扰了我一个星期,仍然与此无关,有人可以帮助我吗?
我使用这样的事件:
core.init()
self.ent_s_send = core.event(core.EV_WRITE,self.conn.fileno(),\
self.ser_send,[self.conn,self.body])
self.ent_s_send.add()
core.dispatch()
The problem happened in my proxy program, Considering G10K I use gevent in my program and I use the low-level gevent.core to run all my function.
Before I change my program into multiple processes. everything is OK. But when I changed it, the problem appears.
I find the problem is that when process NO.2 accept the socket, then the events of process NO.1 will stop dispatch. And if I add a sleep(0.1) in my event, then came a surprise. BUT I lower the sleep time, the problem showed again.
The problem have bothered me for a weeks, still nothing to do with that, Could someone help me ?
I use event like that:
core.init()
self.ent_s_send = core.event(core.EV_WRITE,self.conn.fileno(),\
self.ser_send,[self.conn,self.body])
self.ent_s_send.add()
core.dispatch()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题出在您的代码中,因为 此代码 使用相同的共享套接字工作正常。
当您使用 EV_READ 接受 sa ocket 时,您必须获取客户端套接字并释放对主套接字的控制权;你不能写信给它。您应该使用类似于以下代码的代码:
此后,为此套接字设置 READ 和 WRITE 事件。
I think that the problem is in your code, because this code is working fine, with the same shared socket.
When you accept sa ocket with EV_READ, you must get the client socket and free the control over the main socket; you must not write to it. You should use code similar to the following one:
After this, set READ and WRITE events for this socket.