python: 为什么 diff 在调用 select.epoll() 时处理 return 同一个 epoll 对象
python: Why diff processes return same epoll object when calling select.epoll()
我的目标:启动N个子进程,每个处理不同的套接字集。
-- 这意味着需要不同的 epoll 对象。
问题:当我在子进程中调用 select.epoll() 时,它 returns 同一个对象。
下面是一个简单的例子:
from multiprocessing import Process,Lock
import time,select,os
class A(Process):
def run(self):
fd = select.epoll()
print 'A.pid=',os.getpid(),'poll_fd:', fd, fd.fileno()
while 1:
poll_list = fd.poll(timeout=3600)
for fd,events in poll_list:
pass
class B(Process):
def run(self):
fd = select.epoll()
print 'B.pid=',os.getpid(),'poll_fd:', fd, fd.fileno()
while 1:
poll_list = fd.poll(timeout=3600)
for fd,events in poll_list:
pass
A().start()
B().start()
为什么会这样?
我应该怎么做才能解决它?
任何帮助将不胜感激。?
由于是不同的进程,epoll的资源也不一样。每个进程都有自己的一组文件号。他们为新资源选择了最低的空闲文件号。这就是两个进程使用相同文件号的原因。无需修复。
我的目标:启动N个子进程,每个处理不同的套接字集。
-- 这意味着需要不同的 epoll 对象。
问题:当我在子进程中调用 select.epoll() 时,它 returns 同一个对象。
下面是一个简单的例子:
from multiprocessing import Process,Lock
import time,select,os
class A(Process):
def run(self):
fd = select.epoll()
print 'A.pid=',os.getpid(),'poll_fd:', fd, fd.fileno()
while 1:
poll_list = fd.poll(timeout=3600)
for fd,events in poll_list:
pass
class B(Process):
def run(self):
fd = select.epoll()
print 'B.pid=',os.getpid(),'poll_fd:', fd, fd.fileno()
while 1:
poll_list = fd.poll(timeout=3600)
for fd,events in poll_list:
pass
A().start()
B().start()
为什么会这样?
我应该怎么做才能解决它?
任何帮助将不胜感激。?
由于是不同的进程,epoll的资源也不一样。每个进程都有自己的一组文件号。他们为新资源选择了最低的空闲文件号。这就是两个进程使用相同文件号的原因。无需修复。