0

python 文件名是orientationplot.py 这个文件google 很容易找到。此 python 脚本用于可视化 WindowOrientationListener 在 android 中的行为。但它是为 linux 编写的。我想在 Windows 中使用它。但是有一个错误,我怎样才能让这个文件在windows中运行。

Traceback (most recent call last):
  File "G:\perftool\orientationplot\orientationplot.py", line 27, in <module>
    import fcntl
ImportError: No module named fcntl
fcntl.fcntl(stream, fcntl.F_SETFL, os.O_NONBLOCK)
4

1 回答 1

1

你绝对不能简单地为 Windows 重写这个程序。它大量使用了fcntl模块。如果您不知道,fcntl这是 Linux 上操纵文件描述符的系统调用。

fcntl.fcntl(stream, fcntl.F_SETFL, os.O_NONBLOCK)

nosklo 在这个 StackOverflow 答案中写道:

fcntlon windows的替代品是win32api调用。用法完全不同。这不是您可以翻转的开关。

不过,我确实想指出,通过一些研究,这可能是可能的。您需要弄清楚如何在 Windows 中设置流的文件描述符标志(即流的权限和open() 系统调用指定的其他标志),并设置os.O_NONBLOCK. 我在Winsock 网站上找到了更多信息:

Unix fcntl() 调用在 Winsock 下没有直接等效项。必要时,Winsock 的 ioctlsocket() 调用中存在类似的功能。例如,使用 Unix 的 fcntl() 设置套接字的 O_NONBLOCK 标志的等价物是使用 Winsock 的 ioctlsocket() 设置 FIONBIO 标志。

于 2013-01-10T13:07:37.587 回答