编程语言
首页 > 编程语言> > python-使用命名管道连接到LibreOffice

python-使用命名管道连接到LibreOffice

作者:互联网

我可以使用套接字进行连接,但是我听说在所有内容都是本地的情况下使用管道的速度更快,因此我想尝试一下,但是无法建立连接.

我从Libre开始

 > soffice --headless --invisible --norestore --nodefault --nolockcheck --nofirstwizard --accept='pipe,name=ooo_pipe;urp;'

而应该工作但不起作用的最低限度的最小python脚本是

import uno
from com.sun.star.connection import NoConnectException

pipe = 'ooo_pipe'
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
context = resolver.resolve("uno:pipe,name=%s;urp;StarOffice.ComponentContext" % pipe)

解决方法:

到目前为止,我已经使用了套接字模式.刚刚通过cmd在我的机器上测试了管道:

/usr/lib/openoffice/program/soffice.bin -accept='pipe,name=foo;urp;StarOffice.ServiceManager' -nologo -headless -nofirststartwizard -invisible

$lsof -c soffice|egrep "pipe|foo"
soffice.b 6698 user    3r  FIFO                0,8      0t0 15766935 pipe
soffice.b 6698 user    4w  FIFO                0,8      0t0 15766935 pipe
soffice.b 6698 user   15u  unix 0xffff88009773ed00      0t0 15767001 /tmp/OSL_PIPE_1000_foo

lsof显示存在一个名为socket foo的名称,并且可以通过Python获得连接.在实验开始时,有时不会生成foo,因此会引发com.sun.star.connection.NoConnectException.但是之后我再也无法重复此错误.

我们已经在生产中使用套接字模式无头办公室数年了,它非常稳定且足够快.似乎此处的管道模式仍然依赖于UNIX套接字,因此我建议使用套接字模式.

标签:libreoffice,openoffice-org,named-pipes,uno,python
来源: https://codeday.me/bug/20191101/1984511.html