V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
liuxu
V2EX  ›  Python

我有 Python 连接 openoffice 后,日志里发现 python 连接 openoffice socket 很费时间

  •  
  •   liuxu · 2015-08-03 18:39:55 +08:00 · 1622 次点击
    这是一个创建于 3404 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这么写一个helloworld就贼慢,以后在做pdf,doc等转矢量图那就更慢了,请问有啥办法么?
    日志:
    2015-08-03 18:30:56,804 [CALL,tid 1]: Instantiating pyuno bridge
    2015-08-03 18:30:56,808 [CALL,tid 1]: try py->uno[0x7fd8e9b51c30].createInstanceWithContext((string)"com.sun.star.bridge.UnoUrlResolver", (com.sun.star.uno.XComponentContext)0x7fd8e9bdcd18)
    2015-08-03 18:30:56,809 [CALL,tid 1]: success py->uno[0x7fd8e9b51c30].createInstanceWithContext()=(com.sun.star.uno.XInterface)0x7fd8e9baf288
    2015-08-03 18:30:56,809 [CALL,tid 1]: try py->uno[0x7fd8e9b51e30].resolve((string)"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
    #此处等待30s以上
    2015-08-03 18:31:56,892 [CALL,tid 1]: success py->uno[0x7fd8e9b51e30].resolve()=(com.sun.star.uno.XInterface)0x167e7d8
    2015-08-03 18:31:56,907 [CALL,tid 1]: try py->uno[0x7fd8e9b51d30].createInstanceWithContext((string)"com.sun.star.frame.Desktop", (com.sun.star.uno.XInterface)0x167e7d8)
    2015-08-03 18:31:56,908 [CALL,tid 1]: success py->uno[0x7fd8e9b51d30].createInstanceWithContext()=(com.sun.star.uno.XInterface)0x1687a88
    2015-08-03 18:31:56,928 [CALL,tid 1]: try py->uno[0x7fd8e9b9a038].getCurrentComponent()
    2015-08-03 18:31:56,929 [CALL,tid 1]: success py->uno[0x7fd8e9b9a038].getCurrentComponent()=(com.sun.star.lang.XComponent)0x1696828
    2015-08-03 18:31:56,983 [CALL,tid 1]: try py->uno[0x7fd8e16f6060].createTextCursor()
    2015-08-03 18:31:56,984 [CALL,tid 1]: success py->uno[0x7fd8e16f6060].createTextCursor()=(com.sun.star.text.XTextCursor)0x16d79d8
    2015-08-03 18:31:57,000 [CALL,tid 1]: try py->uno[0x7fd8e16f6060].insertString((com.sun.star.text.XTextCursor)0x16d79d8, (string)"Hello World", (byte)0x0)
    2015-08-03 18:31:57,002 [CALL,tid 1]: success py->uno[0x7fd8e16f6060].insertString()=void


    python程序:

    import socket
    import uno

    #get the uno component from the PyUNO runtime
    localContext = uno.getComponentContext()

    #create the UnoUrlResolver
    resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",localContext)

    #connect to the running office
    ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
    smgr = ctx.ServiceManager

    # get the contral desktop object
    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)

    # access the current writer document
    model = desktop.getCurrentComponent()

    # access the document's text property
    text = model.Text

    # create a cursor
    cursor = text.createTextCursor()

    # Insert the text into the document
    text.insertString(cursor,"Hello World",0)

    # Do a nasty thing before exiting the python process. In case the
    # last call is a oneway call (e.g. see idl-spec of insertString),
    # it must be forced out of the remote-bridge caches before python
    # exits the process. Otherwise, the oneway call may or may not reach
    # the target object.
    # I do this here by calling a cheap synchronous call (getPropertyValue).
    ctx.ServiceManager
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1815 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:33 · PVG 00:33 · LAX 08:33 · JFK 11:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.