Page 1 of 1

[Solved] Terminating an office instance cleanly

Posted: Sat Feb 14, 2015 10:13 pm
by _savage
I've created a new office instance:

Code: Select all

soffice --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
and then connected to it do do some work:

Code: Select all

local = uno.getComponentContext()                                       
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
document = desktop.loadComponentFromURL("file:///path/to/file.odt", "_blank", 0, ())
Now my question is: How do I shut down the whole process cleanly, so that I won't get the "Document recovery" dialog next time around I open office. For now I have something like this:

Code: Select all

document.dispose()
desktop.terminate()
# context.??                                                          
# resolver.??                                                         
# local.??                                                            
os.kill(pid, signal.SIGTERM)

Re: Terminating an office instance cleanly

Posted: Tue Feb 24, 2015 7:45 pm
by _savage
Some supporting documentation is here and here.

At the moment I've changed the code to the following:

Code: Select all

if document.supportsService("com.sun.star.util.XCloseable") :
    document.close(True)
document.dispose()

Re: Terminating an office instance cleanly

Posted: Thu Feb 26, 2015 6:23 pm
by _savage
This question has developed into an interesting thread on the LibreOffice mailing list overe here. I'm going to close this question here, and refer the interested reader to that thread :super:

Re: [Solved] Terminating an office instance cleanly

Posted: Mon Aug 08, 2022 12:51 pm
by NomNomistan
Link doesnt work anymore

Re: [Solved] Terminating an office instance cleanly

Posted: Mon Aug 08, 2022 1:53 pm
by robleyd
Unfortunately that is the way of the internet. A few moments work with a search engine led me to https://listarchives.libreoffice.org/ from whence you might be able to find something relevant.