How to run multiple instances of Writer simultaneously?

Jens Tröger jens.troeger at
Fri Oct 20 02:04:39 UTC 2017

Thank you everybody for your feedback, that was very helpful. Here’s my current working implementation:

- Spawn the soffice process which will function as a “server”

    customenvdir = tempfile.TemporaryDirectory()
    p = subprocess.Popen("soffice --accept=\"pipe,name=SOME_PIPE;url;StarOffice.ServiceManager\" --headless --invisible")

- Terminate the soffice process when I need to

    # I assume that the pipe will be cleaned up as well?
    if customenvdir:                                                                           

- Having soffice running, I can connect to it as usual:

        local = uno.getComponentContext()                                                           
        resolver = local.ServiceManager.createInstanceWithContext("", local)
        context = resolver.resolve("uno:pipe,name=SOME_PIPE;url;StarOffice.ComponentContext")
        desktop = context.ServiceManager.createInstanceWithContext("", context)
        document = desktop.loadComponentFromURL("file://…", "_blank", 0, None)
        controller = document.getCurrentController()                                                    
        pass # Handle

- When done with the document, "close" it down but leave the soffice process untouched and available for more. Here, I am not sure about the other resources that were allocated when documents are being loaded:

    # controller.??                                                                             
    if document:                                                                               
        if has_interface(document, ""):                            
    # desktop.terminate()                                                                      
    # context.??                                                                               
    # resolver.??                                                                              
    # local.??                                                                                 

As Tor suspected, I noticed that desktop.terminate() removes access to the pipe so that others can not open documents anymore. However, it doesn't seem to terminate the soffice process itself.

Also, I have performance concerns for this approach: loading and running through just two documents simultaneously seemed to be unproportionally slow!?

Thank you!

Jens Tröger

More information about the LibreOffice mailing list