在Windows上的select.select中使用sys.stdin [英] Using sys.stdin in select.select on Windows

查看:274
本文介绍了在Windows上的select.select中使用sys.stdin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
可以将select()与Windows下的Python中的文件一起使用?

Possible Duplicate:
Can select() be used with files in Python under Windows?

在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上完成的功能.基本思想是,我与服务器建立了套接字连接,该服务器已将流stdin,stdout,stderr连接到远程运行的进程,并且我正在与本地客户端进行交互,并使其看起来好像本地客户端正在运行过程.

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仅针对套接字定义,不适用于任意文件句柄(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆