python select使用IO多路复用 ,OSError: [WinError 10038]?
最近在学习python,使用select 监听IO多路复用
如下代码,select 第二个参数监听的是文件的操作对象,为啥会报OSError: [WinError 10038] 在一个非套接字上尝试了一个操作? 我是在windows操作系统上运行的。老师的视频是在linux上面运行的,老师的代码运行正常。
from socket import *
from select import select
if __name__ == "__main__":
# 做几个IO用作监控
s = socket()
s.bind(('0.0.0.0', 8888))
s.listen(3)
# 文件操作对象
fd = open('log.txt', 'a+')
rs, ws, xs = select([s], [fd], [])
print("rs", rs)
print("ws", ws)
print("xs", xs)
回复
1个回答

test
2024-07-12
Windows 上 select 不能用于文件。
Note
File objects on Windows are not acceptable, but sockets are. On Windows, the underlying
select()
function is provided by the WinSock library, and does not handle file descriptors that don’t originate from WinSock.
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容