Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么select.select()可以处理磁盘文件,但不能处理epoll()?_Python_Unix_Select_Epoll - Fatal编程技术网

Python 为什么select.select()可以处理磁盘文件,但不能处理epoll()?

Python 为什么select.select()可以处理磁盘文件,但不能处理epoll()?,python,unix,select,epoll,Python,Unix,Select,Epoll,以下代码使用select.select创建文件: f = open('node.py') fd = f.fileno() while True: r, w, e = select.select([fd], [], []) print '>', repr(os.read(fd, 10)) time.sleep(1) 当我尝试使用epoll执行类似操作时,我会遇到一个错误: self._impl.register(fd, events | self.ERROR) IO

以下代码使用select.select创建文件:

f = open('node.py')
fd = f.fileno()
while True:
    r, w, e = select.select([fd], [], [])
    print '>', repr(os.read(fd, 10))
    time.sleep(1)
当我尝试使用epoll执行类似操作时,我会遇到一个错误:

self._impl.register(fd, events | self.ERROR)
IOError: [Errno 1] Operation not permitted 
我还读到epoll不支持磁盘文件,或者说它没有意义

但是为什么select支持磁盘文件呢?我查看了selectmodule.c中的实现,它似乎只是进入了操作系统,即Python没有添加任何特殊支持


在更高的层次上,我正在试验在非阻塞服务器中提供静态文件的最佳方法。我想我会尝试创建I/O线程,从磁盘读取数据并将数据提供给写入套接字的主事件循环线程。

select允许监视指向常规文件的文件描述符,但它总是将文件报告为可读/可写的,即它有些无用,因为它不会告诉您读/写是否会实际阻塞


epoll只是不允许监视常规文件,因为它在linux上没有机制,至少无法判断读取/写入常规文件是否会阻止

Ah OK,因此select循环中的my os.read调用正在阻止。有道理。@user1117755是的,如果必须等待硬盘驱动器,它将被阻塞。