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/
Context
- Re: How to run multiple instances of Writer simultaneously? (continued)
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.