可能重复:
windows下python中的文件可以用select()吗?
在 UNIX 上,我可以在 Python 中将 sys.stdin
传递给 select.select
.我正在尝试在 Windows 上执行此操作,但 Windows 上 Python 中的 select.select
不允许这样做.
On UNIX I am able to pass sys.stdin
to select.select
in Python. I am attempting to do this on Windows, but select.select
in Python on Windows will not allow it.
要更准确地描述我在做什么,请参阅 https://github.com/eldarion/gondor-client/blob/ccbbf9d4b61ecbc2f66f510b993eb5fba0d81c09/gondor/run.py.
To more accurately describe what I am doing see https://github.com/eldarion/gondor-client/blob/ccbbf9d4b61ecbc2f66f510b993eb5fba0d81c09/gondor/run.py.
unix_run_poll
函数是我试图在 Windows 上完成的.基本思想是,我有一个到服务器的套接字连接,该服务器已将流式标准输入、标准输出、标准错误连接到远程运行的进程,并且我从本地客户端与它进行交互,并使其看起来好像本地客户端正在运行过程.
The unix_run_poll
function is what I am trying to accomplish on Windows. The basic idea is that I have a socket connection to a server which has hooked up streaming stdin, stdout, stderr to a process running remotely and I am interacting with it from the local client and making it appear as if the local client is running the process.
win32_run_poll
是我尝试将它移植到 Windows 的尝试,它确实可以工作.这有点不稳定,而且 IMO 的方法非常糟糕.
The win32_run_poll
is my attempt at porting it to Windows and it does work, sort of. It is a little wonky and the approach, IMO, is very bad.
有人对如何改进有建议吗?对win32api的依赖不太理想,但我可以保留它.
Does anyone have suggestions on how this can be improved? The dependency on win32api is less than ideal, but I am okay with keeping it.
Windows上select
只针对socket定义,对任意文件句柄无效(windows没有文件描述符的概念).有关此问题的详细信息,请参阅 msdn 文档,在 python 文档中也提到了 select 模块.
On Windows select
is only defined for sockets, and will not work for arbitrary file handles (windows has no concept of file descriptors). For more information about this issue, see the msdn documentation, it is also mentioned in the python documentation for the select module.
如果你想对任意文件使用轮询,你应该研究一些抽象轮询套接字和文件句柄的东西.这可能是您帖子的评论中提到的扭曲反应器,也可能是与 libuv 或其他一些绑定的 python 绑定您选择的事件库.
If you want to use polling for arbitary files, you should look into something that abstracts polling sockets and file handles. This might be the twisted reactor referred to in a comment to your post, or it might be a python binding to libuv, or some other event library of your choice.
这篇关于在 Windows 上的 select.select 中使用 sys.stdin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!