How to run multiple instances of Writer simultaneously?
jens.troeger at light-speed.de
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?
- Having soffice running, I can connect to it as usual:
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:pipe,name=SOME_PIPE;url;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", 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:
if has_interface(document, "com.sun.star.util.XCloseable"):
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!?
More information about the LibreOffice