开发者

why a new process entry then the events of old process stop running when sharing a listening socket for multiple processes?

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.s开发者_如何学Pythoner_send,[self.conn,self.body])
    self.ent_s_send.add()
    core.dispatch()


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:

try:
    client_socket, address = sock.accept()
except socket.error, err:
    if err[0] == errno.EAGAIN:
        sys.exc_clear()
        return
    raise
core.event(core.EV_READ, client_socket.fileno(), callback)
core.event(core.EV_WRITE, client_socket.fileno(), callback)
core.event(core.EV_READ | core.EV_WRITE, client_socket.fileno(), callback)

After this, set READ and WRITE events for this socket.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜