如何在windows上处理这个python文件?

2024-10-01 09:19:41 发布

您现在位置:Python中文网/ 问答频道 /正文

python文件名是方向图.py 这个文件很容易被谷歌找到。 这个python脚本用于可视化android中WindowOrientationListener的行为。 但它是为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)

Tags: 文件py脚本文件名linuxwindows可视化错误
1条回答
网友
1楼 · 发布于 2024-10-01 09:19:41

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

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

nosklo在this StackOverflow answer中写道:

^{bq}$

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

The Unix fcntl() call has no direct equivalent under Winsock. Where necessary, similar functionality exists in Winsock’s ioctlsocket() call. For example, the equivalent of using Unix’s fcntl() to set a socket’s O_NONBLOCK flag is setting the FIONBIO flag with Winsock’s ioctlsocket().

相关问题 更多 >