python 不同子进程为何创建出相同的epoll对象
PHPz
PHPz 2017-04-17 17:49:53
0
1
393

我的目的:不同的进程分别等待不同的socket集合
遇到的问题:我在不同的子进程分别调用 select.epoll(),结果居然返回同一个object!
简单的例子如下:

from multiprocessing import Process,Lock
import time,select

class A(Process):
    def run(self):
        fd = select.epoll()
        print 'A poll_fd:', fd, fd.fileno()
        while 1: time.sleep(3600)

class B(Process):
    def run(self):
        fd = select.epoll()
        print 'B poll_fd:', fd, fd.fileno()
        while 1: time.sleep(3600)

A().start()
B().start()

运行后输出结果如下:

[root@localhost x]# ./test.py 
A poll_fd: <select.epoll object at 0x7f2c4de49150> 4
B poll_fd: <select.epoll object at 0x7f2c4de49150> 4

一个socket可读写,所有子进程都被唤醒了……
有谁遇到过么?请问怎么解决呢?

PHPz
PHPz

学习是最好的投资!

reply all(1)
伊谢尔伦

Just because the id and fileno of two fds are the same, it does not mean that they are two identical objects.

A and B are two different processes. The two fds belong to different process spaces and are not the same.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template