从 Python 运行 Xvfb
我正在一台没有 X 服务器的服务器上工作,并尝试运行一个使用spynner 模块的脚本,这需要 X 服务器。为此,我想运行 Xvfb。
我可以通过 xvfb-run 调用它来运行脚本,即:
xvfb-run python2.6 try.py.
这没有问题。但是,我需要从脚本内调用 Xvfb。为此,我尝试使用子进程,如下所示:
xvfb = subprocess.Popen(['Xvfb', ':99'])
将这段代码添加到脚本的开头,并在
python2.6 try.py
收到消息时尝试运行脚本:
: cannot connect to X server
还有其他我需要做的事情吗?提前致谢。
I am working on a server with no X servers and trying to run a script that uses spynner module, which requires an X server. For this purpose, I want to run Xvfb.
I can run the script by calling it via xvfb-run
, i.e.:
xvfb-run python2.6 try.py.
This works with no problem. However, I need to invoke Xvfb from within the script. For this purpose, I tried using subprocess as follows:
xvfb = subprocess.Popen(['Xvfb', ':99'])
After adding this piece of code to the beginning of the script, and trying to run the script as
python2.6 try.py
I get the message:
: cannot connect to X server
Is there something else I need to do? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于未来的访问者,值得一提的是 PyVirtualDisplay 提供了 Xvfb 的抽象,使其易于使用Python。
For future visitors, it is worth mentioning that PyVirtualDisplay offers an abstraction over Xvfb to make it easy to use from Python.
您需要添加:
以便当它打开与 X 服务器的连接时,它将能够找到您已启动的 Xvfb 实例
you'll need to add:
so that when it goes to open the connection to the X server it'll be able to find the Xvfb instance you've started