[Solved] Terminating an office instance cleanly

The Application Programming Interface and the OASIS Open Document Format

[Solved] Terminating an office instance cleanly

Postby _savage » Sat Feb 14, 2015 10:13 pm

I've created a new office instance:

Code: Select all   Expand viewCollapse view
soffice --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"

and then connected to it do do some work:

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
document.dispose()
desktop.terminate()
# context.??                                                         
# resolver.??                                                         
# local.??                                                           
os.kill(pid, signal.SIGTERM)
Last edited by Hagar Delest on Thu Feb 26, 2015 11:21 pm, edited 1 time in total.
Reason: tagged [Solved].
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 138
Joined: Sun Apr 21, 2013 12:55 am

Re: Terminating an office instance cleanly

Postby _savage » Tue Feb 24, 2015 7:45 pm

Some supporting documentation is here and here.

At the moment I've changed the code to the following:
Code: Select all   Expand viewCollapse view
if document.supportsService("com.sun.star.util.XCloseable") :
    document.close(True)
document.dispose()
Last edited by _savage on Thu Feb 26, 2015 6:23 pm, edited 1 time in total.
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 138
Joined: Sun Apr 21, 2013 12:55 am

Re: Terminating an office instance cleanly

Postby _savage » Thu Feb 26, 2015 6:23 pm

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:
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 138
Joined: Sun Apr 21, 2013 12:55 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest