How to run multiple instances of Writer simultaneously?
Jens Tröger
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
p.terminate()
# I assume that the pipe will be cleaned up as well?
if customenvdir:
cleanup_tmp(customenvdir)
- Having soffice running, I can connect to it as usual:
try:
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()
except:
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:
# https://forum.openoffice.org/en/forum/viewtopic.php?f=25&t=75367
if has_interface(document, "com.sun.star.util.XCloseable"):
document.close(True)
else:
document.dispose()
# 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
--
Jens Tröger
http://savage.light-speed.de/
More information about the LibreOffice
mailing list