Python:在Cygwin中从文件/流中读取非阻塞

时间:2016-01-09 16:56:50

标签: python terminal cygwin

如果我在Unix系统上,那么我可以用Python做这样的事情来打开非阻塞模式的文件:

fd = os.open(filepath, os.O_NONBLOCK)

但是,在Windows中,os.O_NONBLOCK不存在,如果我们尝试使用它,则会遇到os模块错误'module' object has no attribute O_NONBLOCK。对于非阻塞输入,我们必须执行类似的操作:https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/terminal/win32_input.py#L99

虽然非阻塞输入如何在Cygwin中工作? Cygwin是否模仿类似O_NONBLOCK选项的内容?

1 个答案:

答案 0 :(得分:0)

O_NONBLOCK可用于C编程。您可以在头文件/usr/include/sys/_default_fcntl.h中看到定义

#define _FNONBLOCK  0x4000  /* non blocking I/O (POSIX style) */
#define O_NONBLOCK  _FNONBLOCK

您可以直接尝试幻数0x4000。