问题
If I was on a Unix system, then I could do something like this in Python to open a file in non-blocking mode:
fd = os.open(filepath, os.O_NONBLOCK)
However, in Windows, os.O_NONBLOCK does not exist, and one would get an os module error 'module' object has no attribute O_NONBLOCK, if we tried to use it. We would have to do something like this for non-blocking input: https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/terminal/win32_input.py#L99
How does non-blocking input work in Cygwin though? Does Cygwin emulate something similar to the O_NONBLOCK option?
回答1:
O_NONBLOCK can be used in C programming. You can see the definitions in the header file /usr/include/sys/_default_fcntl.h
#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
#define O_NONBLOCK _FNONBLOCK
You could try the magic number 0x4000 directly.
来源:https://stackoverflow.com/questions/34696267/python-non-blocking-read-from-file-stream-in-cygwin